Skip to content

Commit cfd873c

Browse files
authored
Remove test only MapperBuilderContext constructor (#109964)
MapperBuilderContext has a constructor that is only used in 3 places by tests. It is misleading in that it sets hardcoded values for most of the arguments that are necessary to create a meaningful context object. There's the risk that it gets called from production code, which we want to avoid, hence this commit removes such constructor in favour of moving the constants to test code.
1 parent 9335566 commit cfd873c

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

server/src/main/java/org/elasticsearch/index/mapper/MapperBuilderContext.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ public static MapperBuilderContext root(boolean isSourceSynthetic, boolean isDat
3737
private final ObjectMapper.Dynamic dynamic;
3838
private final MergeReason mergeReason;
3939

40-
MapperBuilderContext(String path) {
41-
this(path, false, false, false, ObjectMapper.Defaults.DYNAMIC, MergeReason.MAPPING_UPDATE);
42-
}
43-
4440
MapperBuilderContext(
4541
String path,
4642
boolean isSourceSynthetic,

server/src/test/java/org/elasticsearch/index/mapper/FieldAliasMapperValidationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void testFieldAliasWithDifferentNestedScopes() {
159159

160160
private static FieldMapper createFieldMapper(String parent, String name) {
161161
return new BooleanFieldMapper.Builder(name, ScriptCompiler.NONE, false, IndexVersion.current()).build(
162-
new MapperBuilderContext(parent)
162+
new MapperBuilderContext(parent, false, false, false, ObjectMapper.Defaults.DYNAMIC, MapperService.MergeReason.MAPPING_UPDATE)
163163
);
164164
}
165165

server/src/test/java/org/elasticsearch/index/mapper/ObjectMapperMergeTests.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,16 @@ private static RootObjectMapper createRootSubobjectFalseLeafWithDots() {
332332

333333
private static ObjectMapper.Builder createObjectSubobjectsFalseLeafWithDots() {
334334
KeywordFieldMapper.Builder fieldBuilder = new KeywordFieldMapper.Builder("host.name", IndexVersion.current());
335-
KeywordFieldMapper fieldMapper = fieldBuilder.build(new MapperBuilderContext("foo.metrics"));
335+
KeywordFieldMapper fieldMapper = fieldBuilder.build(
336+
new MapperBuilderContext(
337+
"foo.metrics",
338+
false,
339+
false,
340+
false,
341+
ObjectMapper.Defaults.DYNAMIC,
342+
MapperService.MergeReason.MAPPING_UPDATE
343+
)
344+
);
336345
assertEquals("host.name", fieldMapper.simpleName());
337346
assertEquals("foo.metrics.host.name", fieldMapper.name());
338347
return new ObjectMapper.Builder("foo", ObjectMapper.Defaults.SUBOBJECTS).add(
@@ -342,7 +351,16 @@ private static ObjectMapper.Builder createObjectSubobjectsFalseLeafWithDots() {
342351

343352
private ObjectMapper.Builder createObjectSubobjectsFalseLeafWithMultiField() {
344353
TextFieldMapper.Builder fieldBuilder = createTextKeywordMultiField("host.name");
345-
TextFieldMapper textKeywordMultiField = fieldBuilder.build(new MapperBuilderContext("foo.metrics"));
354+
TextFieldMapper textKeywordMultiField = fieldBuilder.build(
355+
new MapperBuilderContext(
356+
"foo.metrics",
357+
false,
358+
false,
359+
false,
360+
ObjectMapper.Defaults.DYNAMIC,
361+
MapperService.MergeReason.MAPPING_UPDATE
362+
)
363+
);
346364
assertEquals("host.name", textKeywordMultiField.simpleName());
347365
assertEquals("foo.metrics.host.name", textKeywordMultiField.name());
348366
FieldMapper fieldMapper = textKeywordMultiField.multiFields.iterator().next();

0 commit comments

Comments
 (0)