-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NPE in CompositeGrammer.getIndirectDelegates in Java 8 #151
Comments
Also see the java issue where this problem was discussed. They considered backing out the change (so that it would continue to be safe for antlr3 to pass null to removeAll), but decided against it. |
What they should have done is report the issue here, so it would get fixed. Wow. |
Yeah I was stunned when I saw that no one had bothered to report it here. I thought for sure I had just missed it, and had to look back through all the reported issues here to make sure I was not filing a duplicate. |
The fix here is trivial, but I figure I might as well provide a patch anyway. Patch to be applied to CompositeGrammar.java:
My guess is that when Java 8 comes out (on March 18), other people will start to run into this. |
makes sense. fixed. |
Before the change, preon was complaining of a NullPointerException in CompositeGrammer.getIndirectDelegates. Please see antlr/antlr3#151 for more information on this bug that has been resolved in ANTLR 3.5.2
To fix antlr/antlr3#151 error(10): internal error: Can't get property indirectDelegates using method get/isIndirectDelegates from org.antlr.tool.Grammar instance : java.lang.NullPointerException
In the class org.antlr.tool.CompositeGrammar, in the method getIndirectDelegates, there is a call to java.util.ArrayList.removeAll with an argument that might be null.
In Java 7, this can sometimes be okay: ArrayList.removeAll(null) is a no-op if the list you are removing from is empty. But starting with Java 8, it's never okay: ArrayList.removeAll(null) will always throw NullPointerException. When I upgraded my build to use Java 8, it started failing with this NPE.
I suggest that a check should be added to getIndirectDelegates so that the call to removeAll (line 226, in the source I'm seeing) only happens if direct is not null. And, for that matter, if delegates is also not null.
I get this in antlr versions 3.2 and 3.5.1.
Here's a partial stack trace:
java.lang.NullPointerException
at java.util.Objects.requireNonNull(Objects.java:203)
at java.util.ArrayList.removeAll(ArrayList.java:674)
at org.antlr.tool.CompositeGrammar.getIndirectDelegates(CompositeGrammar.java:226)
at org.antlr.tool.Grammar.getIndirectDelegates(Grammar.java:2722)
The text was updated successfully, but these errors were encountered: