[antlr-interest] Problem in BaseAST.equals
Smith, Eric V.
ericsmith at windsor.com
Fri Aug 30 18:01:06 PDT 2002
Wouldn't you also need to check that t.getText() is not null?
> -----Original Message-----
> From: richardhensley99 [mailto:richard.hensley at mckesson.com]
> Sent: Friday, August 30, 2002 8:51 PM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] Problem in BaseAST.equals
>
>
> I was just chasing down an NPE problem in my code, and I chased it
> down to the following method of BaseAST:
>
> /** Is node t equal to this in terms of token type and text?
> */ public boolean equals(AST t) {
> if (t == null) return false;
> return this.getText().equals(t.getText()) &&
> this.getType() == t.getType();
> }
>
> I think this code should be changed to read as follows
>
> /** Is node t equal to this in terms of token type and text?
> */ public boolean equals(AST t) {
> if (t == null) return false;
> return this.getText() != null &&
> this.getText().equals(t.getText()) &&
> this.getType() == t.getType();
> }
>
> The problem is that I was trying to compare two nodes of type EOF.
> Apparently an EOF type node has a null text component, and thus this
> code blows with an NPE.
>
> I was writing code to compare two AST trees for testing before I
> discovered equalsTree. What I can't figure out is why equalsTree
> doesn't seem to have an NPE.
>
> Richard
>
>
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
>
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list