[antlr-interest] ANTLR 3.0b4: NullPointerException in NFAToDFAConverter
Terence Parr
parrt at cs.usfca.edu
Thu Sep 14 14:19:25 PDT 2006
On Sep 14, 2006, at 7:57 AM, Raffael Herzog wrote:
> Hi,
>
> 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
> NPE.
>
> 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)) )
Hi Raffi,
Thanks! You are right! Changed to:
// we already have an accept state for alt;
// Are their gate sem pred contexts the same?
// For now we assume a braindead version: both must not
// have gated preds or share exactly same single gated pred.
// The equals() method is only defined on Predicate contexts not
// OR etc...
SemanticContext gatedPreds = d.getGatedPredicatesInNFAConfigurations();
SemanticContext existingStateGatedPreds =
acceptStateForAlt.getGatedPredicatesInNFAConfigurations();
if ( (gatedPreds==null && existingStateGatedPreds==null) ||
((gatedPreds!=null && existingStateGatedPreds!=null) &&
gatedPreds.equals(existingStateGatedPreds)) )
Ter
More information about the antlr-interest
mailing list