As of b99, TreePath.iterator() is implemented as follows, and as you see it's guaranteed to cause NPE because curr is not initialized to this. Also, it fails to iterate the leaf node correctly:
public Iterator<Tree> iterator() {
return new Iterator<Tree>() {
public boolean hasNext() {
return curr.parent != null;
}
public Tree next() {
curr = curr.parent;
return curr.leaf;
}
public void remove() {
throw new UnsupportedOperationException();
}
private TreePath curr;
};
}
The correct implementation is:
public Iterator<Tree> iterator() {
return new Iterator<Tree>() {
public boolean hasNext() {
return curr != null;
}
public Tree next() {
TreePath t = curr;
curr = curr.parent;
return t.leaf;
}
public void remove() {
throw new UnsupportedOperationException();
}
private TreePath curr = TreePath.this;
};
}
The iterator method should also document in which order Trees are iterated. I find it more useful to be able to iterate from root to leaf, but no matter which way it goes, it should be documented.