Skip to content

NPE in CompositeGrammer.getIndirectDelegates in Java 8 #151

@druidsquirrel

Description

@druidsquirrel

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)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions