You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by bu...@apache.org on 2002/10/08 18:45:32 UTC

DO NOT REPLY [Bug 13062] - removeChild failes when a NPE when a NodeIterator is attached

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13062>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13062

removeChild failes when a NPE when a NodeIterator is attached





------- Additional Comments From david_iom@hotmail.com  2002-10-08 16:45 -------
The problem arises when any NodeIterator has not been detatches after its use 
or has never been called and you want to remove a node from the tree.

At removal of a node, the node will first be removed from all iterators. If 
however the iterator has reached it's end "fCurrentNode=null" (and not been 
detached). This gife rise to a NullPointerException in the method 
matchNodeOrParent (in the second pass through the for loop when executing 
n.getParentNode() )

current:
    Node matchNodeOrParent(Node node) {
        for (Node n = fCurrentNode; n != fRoot; n = n.getParentNode()) {
            if (node == n) return n;
        }
        return null;
    }
possible fix:
    Node matchNodeOrParent(Node node) {
        if (fCurrentNode == null) return null;

        for (Node n = fCurrentNode; n != fRoot; n = n.getParentNode()) {
            if (node == n) return n;
        }
        return null;
    }

I found this problem when trying out Xerces_2.2.0 on code previously running 
under Xerces_1.4.4.
I use NodeIterators extensivly and have failed to call the detach() method.
Then i try to the method "node.insertBefore(newNode, refNode)"
This will eventually take me to  matchNodeOrParent and the NullPointerException

I beleve a NullPointerException is a bug in this situation. One could argue 
that the wrong use of NodeIterator is to blame, if so I would prefere an 
exception that told me so.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org