[
https://issues.apache.org/jira/browse/AVRO-4182?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18081305#comment-18081305
]
ASF subversion and git services commented on AVRO-4182:
-------------------------------------------------------
Commit 30c81a354dee27396f1e86d79dfbb819bb7388a4 in avro's branch
refs/heads/branch-1.12 from Oscar Westra van Holthe - Kind
[ https://gitbox.apache.org/repos/asf?p=avro.git;h=30c81a354d ]
AVRO-4182: Avoid ANTLR parsing edge cases (#3756)
In some cases, enter and exit rules are not called in pairs while parsing.
Apparently, this is by design. This fix adds a test that the fix does indeed
work (it tests an exception, as the error does not show up with a duplicated
definition).
Note: this change keeps the entire parse tree in memory during parsing,
and allows it to be collected directly afterwards.
(cherry picked from commit 34bdcf98ab5d0639219f4d1ec144828e0bfa58fe)
> NoSuchElementException in IdlReader for duplicated Enum definition
> ------------------------------------------------------------------
>
> Key: AVRO-4182
> URL: https://issues.apache.org/jira/browse/AVRO-4182
> Project: Apache Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.12.0
> Reporter: Raphael Rösch
> Assignee: Oscar Westra van Holthe - Kind
> Priority: Major
> Labels: pull-request-available
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> Given this avdl (TestProtocol.avdl):
> {noformat}
> protocol TestProtocol {
> enum Foo {
> UNKNOWN,
> BAR
> } = UNKNOWN;
> enum Foo {
> UNKNOWN,
> BAZ
> } = UNKNOWN;
> }
> {noformat}
> With Avro 1.12.0 'IdlReader' fails with NoSuchElementException
> {noformat}
> $ java -jar ./avro-tools-1.12.0.jar idl ./TestProtocol.avdl
> Exception in thread "main" org.apache.avro.SchemaParseException:
> java.util.NoSuchElementException
> at org.apache.avro.idl.IdlReader.parse(IdlReader.java:224)
> at org.apache.avro.idl.IdlReader.parse(IdlReader.java:187)
> at org.apache.avro.idl.IdlReader.parse(IdlReader.java:172)
> at org.apache.avro.tool.IdlTool.run(IdlTool.java:70)
> at org.apache.avro.tool.Main.run(Main.java:67)
> at org.apache.avro.tool.Main.main(Main.java:56)
> Caused by: java.util.NoSuchElementException
> at java.base/java.util.ArrayDeque.removeFirst(ArrayDeque.java:360)
> at java.base/java.util.ArrayDeque.pop(ArrayDeque.java:591)
> at
> org.apache.avro.idl.IdlReader$IdlParserListener.exitEnumDeclaration(IdlReader.java:531)
> at
> org.apache.avro.idl.IdlParser$EnumDeclarationContext.exitRule(IdlParser.java:976)
> at org.antlr.v4.runtime.Parser.triggerExitRuleEvent(Parser.java:410)
> at org.antlr.v4.runtime.Parser.exitRule(Parser.java:642)
> at org.apache.avro.idl.IdlParser.idlFile(IdlParser.java:289)
> at org.apache.avro.idl.IdlReader.parse(IdlReader.java:220)
> ... 5 more
> {noformat}
> * This does also happen if the Enums are defined in two different Protocols
> of the same namespace.
> * Having multiple Enums of the same name should not be allowed. The parse
> must therefore fail, but print a more helpful error message.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)