Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ protected boolean processField(RootObjectMapper.Builder builder, String fieldNam
}
]
*/
if ((fieldNode instanceof List) == false) {
throw new MapperParsingException("Dynamic template syntax error, expects an array of named objects");
}
List<?> tmplNodes = (List<?>) fieldNode;
List<DynamicTemplate> templates = new ArrayList<>();
for (Object tmplNode : tmplNodes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,21 @@ public void testIllegalFormatField() throws Exception {
assertEquals("Invalid format: [[test_format]]: expected string value", e.getMessage());
}
}

public void testIllegalDynamicTemplates() throws Exception {
String mapping = Strings.toString(XContentFactory.jsonBuilder()
.startObject()
.startObject("type")
.startObject("dynamic_templates")
.endObject()
.endObject()
.endObject());

DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
MapperParsingException e = expectThrows(MapperParsingException.class,
() -> parser.parse("type", new CompressedXContent(mapping)));
assertEquals("Dynamic template syntax error, expects an array of named objects", e.getMessage());
}
}

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

This closing bracket is too much now, class closed in line 203 already so the test doesn't compile. Please remove the last two lines so the class compiles.