Project

Profile

Help

Revision 4509645d

Added by Michael Kay over 12 years ago

Fix bug 2688388 - NPE in getRoot() on linked tree

View differences:

latest9.1/bj/net/sf/saxon/tree/NodeImpl.java
607 607
     */
608 608

  
609 609
    public NodeInfo getRoot() {
610
        return getParent().getRoot();
610
        NodeInfo parent = getParent();
611
        if (parent == null) {
612
            return this;
613
        } else {
614
            return parent.getRoot();
615
        }
611 616
    }
612 617

  
613 618
    /**
614 619
     * Get the root (document) node
615
     *
616
     * @return the DocumentInfo representing the containing document
620
     * @return the DocumentInfo representing the containing document. If this
621
     *     node is part of a tree that does not have a document node as its
622
     *     root, returns null.
617 623
     */
618 624

  
619 625
    public DocumentInfo getDocumentRoot() {
620
        return getParent().getDocumentRoot();
626
        NodeInfo parent = getParent();
627
        if (parent == null) {
628
            return null;
629
        } else {
630
            return parent.getDocumentRoot();
631
        }
621 632
    }
622 633

  
634

  
623 635
    /**
624 636
     * Get the physical root of the tree. This may be an imaginary document node: this method
625 637
     * should be used only when control information held at the physical root is required

Also available in: Unified diff