[antlr-interest] ANTLR 3.0b4: NullPointerException in NFAToDFAConverter

Raffael Herzog devnull at raffael.ch
Thu Sep 14 07:57:09 PDT 2006


I suddenly run into an NPE at line 989 of NFAToDFAConverter when I try
to compile my syntax with antlr 3.0b4.

Looking at the code, it's rather obvious that this code can't be right:

if ( (gatedPreds==null && existingStateGatedPreds==null) ||
    (gatedPreds!=null && existingStateGatedPreds!=null) ||
    gatedPreds.equals(existingStateGatedPreds) )

If both are null, evaluation will stop with true. If both are non-null,
evaluation will also stop with true. So, if we get the the equals
statement, we know for sure that one of them is null, so we also know
that this equals statement will either evaluate to false or throw an

Probably, this should be a null-safe equals. If so, a corrected version
of this if statement could look like this:

if ( (gatedPreds==null && existingStateGatedPreds==null) ||
    (!(gatedPreds==null ^ existingStateGatedPreds==null) &&
    gatedPreds.equals(existingStateGatedPreds)) )


More information about the antlr-interest mailing list