[antlr-interest] Avoiding ClassCastExceptions in org.antlr.runtime.tree.BaseTree (Limitation in ANTLR v 3.1)
Tim Halloran
hallorant at gmail.com
Wed Sep 24 11:03:54 PDT 2008
I'm using the standard Tree implementations (extending BaseTree) in
combination with a custom implementation of Tree. The problem is that
BaseTree assumes that it is only being used with subclasses of BaseTree
despite it's implementation really not needing to make this assumption. I
propose fixing the code to eliminate this problem.
I modified the getChild() and toStringTree() methods in BaseTree.java. I
changed lines 56 and 297 to cast to Tree, instead of BaseTree. For example:
public Tree getChild(int i) {
if ( children==null || i>=children.size() ) {
return null;
}
return (Tree) children.get(i); // line 56
}
There might be some other places to change, but I have only encountered
problems with these.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080924/239ca594/attachment.html
More information about the antlr-interest
mailing list