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

http://issues.apache.org/bugzilla/show_bug.cgi?id=30715

...xml.dom.traversal.TreeWalkerImpl.nextNode hangs forever - patch supplied

           Summary: ...xml.dom.traversal.TreeWalkerImpl.nextNode hangs
                    forever - patch supplied
           Product: Xindice
           Version: cvs head (1.1)
          Platform: All
        OS/Version: Other
            Status: NEW
          Severity: Major
          Priority: Other
         Component: DB Engine
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


Heres a fixed version of the function. The problem was that after
node.getParentNode() this already accepted node was returned again, leading to
an endless loop and an OutOfMemory after some time.

Replacing nextNode with this function fixed the problem:

------------ PATCH ----------------------------------------------

    public Node nextNode() {
        Node result = null;
        if (next != null) {
            result = next;
        } else {
            return null;
        }
        
        Node node = next;
        while (true) {
            if (node.hasChildNodes()) {
                // Go deeper...
                node = node.getFirstChild();
            } else {
                // Go further 
                while (true) {
                    Node old = node;
                    node = node.getNextSibling();                    
                    if (node == null) {
                        // Else go up and further...
                        do { 
                                node = old;
                                node = node.getParentNode();
                            if (node == null) {
                                    next = null;
                                return result;
                                }
                                // Take the next sibling of the parent,
                                // because the parent has already been
                                // visited
                                                        old = node;
                                node = node.getNextSibling();
                                                } while( node == null );
                    } else
                        break;
                }
            }
            if (node != null && acceptNode(node)) {
                next = node;
                return result;
            }
        }
    }

Reply via email to