Skip to content
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

Closed
druidsquirrel opened this issue Feb 15, 2014 · 5 comments
Closed

NPE in CompositeGrammer.getIndirectDelegates in Java 8 #151

druidsquirrel opened this issue Feb 15, 2014 · 5 comments
Assignees
Milestone

Comments

@druidsquirrel
Copy link

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)

@druidsquirrel
Copy link
Author

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.

http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8015656

@sharwell sharwell added this to the ANTLR 3.5.2 milestone Feb 15, 2014
@sharwell sharwell self-assigned this Feb 15, 2014
@sharwell
Copy link
Member

What they should have done is report the issue here, so it would get fixed. Wow.

@druidsquirrel
Copy link
Author

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.

@druidsquirrel
Copy link
Author

The fix here is trivial, but I figure I might as well provide a patch anyway. Patch to be applied to CompositeGrammar.java:

226c226,227
<       delegates.removeAll(direct);
---
>       if (direct != null)
>           delegates.removeAll(direct);

My guess is that when Java 8 comes out (on March 18), other people will start to run into this.

@parrt parrt closed this as completed in e88907c Feb 19, 2014
@parrt
Copy link
Member

parrt commented Feb 19, 2014

makes sense. fixed.

@sharwell sharwell assigned parrt and unassigned sharwell Mar 13, 2014
asfgit pushed a commit to apache/tapestry-5 that referenced this issue Jul 1, 2014
jdl17 pushed a commit to jdl17/preon that referenced this issue Jul 29, 2015
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
xtexChooser added a commit to AOSC-Tracking/jfx8u that referenced this issue Aug 9, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants