diff --git a/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java index 4088f654d80..4b162b0423d 100755 --- a/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -64,7 +64,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -76,6 +75,7 @@ import java.util.function.Function; import static java.util.Collections.emptySet; import static java.util.Collections.unmodifiableSet; import static org.elasticsearch.common.collect.MapBuilder.newMapBuilder; +import static org.elasticsearch.common.util.set.Sets.newHashSetCopyWith; /** * @@ -288,10 +288,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable { } mappers = newMapBuilder(mappers).put(mapper.type(), mapper).map(); if (mapper.parentFieldMapper().active()) { - Set parentTypesCopy = new HashSet(); - parentTypesCopy.addAll(parentTypes); - parentTypesCopy.add(mapper.parentFieldMapper().type()); - parentTypes = unmodifiableSet(parentTypesCopy); + parentTypes = unmodifiableSet(newHashSetCopyWith(parentTypes, mapper.parentFieldMapper().type())); } assert assertSerialization(mapper); return mapper;