KalleOlaviNiemitalo commented on code in PR #1748:
URL: https://github.com/apache/avro/pull/1748#discussion_r911727624
##########
lang/java/avro/src/main/java/org/apache/avro/Schema.java:
##########
@@ -1454,19 +1456,37 @@ public Schema parse(String s, String... more) {
*/
public Schema parse(String s) {
try {
- return parse(FACTORY.createParser(s));
+ return parse(FACTORY.createParser(s), false);
} catch (IOException e) {
throw new SchemaParseException(e);
}
}
- private Schema parse(JsonParser parser) throws IOException {
+ private Schema parse(JsonParser parser, boolean allowDanglingContent)
throws IOException {
boolean saved = validateNames.get();
boolean savedValidateDefaults = VALIDATE_DEFAULTS.get();
try {
validateNames.set(validate);
VALIDATE_DEFAULTS.set(validateDefaults);
- return Schema.parse(MAPPER.readTree(parser), names);
+ JsonNode jsonNode = MAPPER.readTree(parser);
+ Schema schema = Schema.parse(jsonNode, names);
+ if (!allowDanglingContent) {
+ StringWriter danglingWriter = new StringWriter();
+ parser.releaseBuffered(danglingWriter);
+ String dangling = danglingWriter.toString().trim();
+ if (dangling.isEmpty()) {
Review Comment:
Could perhaps optimise by doing the ByteArrayOutputStream stuff only if the
first releaseBuffered call returns exactly -1.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]