Commons JXPath
  1. Commons JXPath
  2. JXPATH-113

NullPointerException in ChildContext when document only contains an empty root node

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.4
    • Labels:
      None

      Description

      In ChildContext I get a NullPointerException, the error appears in method prepare()

          iterator = (startFromParentLocation ? parent.getParent() : parent).childIterator(nodeTest,
                      reverse, startFromParentLocation ? parent : null);
      

      should be changed in my opinion to

      final NodePointer actualParent = startFromParentLocation ? parent.getParent() : parent;
              iterator = actualParent==null ? null : actualParent.childIterator(nodeTest,
                      reverse, startFromParentLocation ? parent : null);
      

      The tests triggering the error are testIssue172_CountFollowingSiblingNode and testIssue172_CountPrecedingSiblingNode

        Activity

        Hide
        Benedikt Ritter added a comment -
        $ svn ci -m "JXPATH-113: NullPointerException in ChildContext when document only contains an empty root node. Thanks to Michele Vivoda. This also fixes #1 from github."
        Sending        src/changes/changes.xml
        Sending        src/main/java/org/apache/commons/jxpath/ri/axes/ChildContext.java
        Adding         src/test/java/org/apache/commons/jxpath/issues/JXPath113Test.java
        Transmitting file data ...
        Committed revision 1716226.
        

        Thank you!

        Show
        Benedikt Ritter added a comment - $ svn ci -m "JXPATH-113: NullPointerException in ChildContext when document only contains an empty root node. Thanks to Michele Vivoda. This also fixes #1 from github." Sending src/changes/changes.xml Sending src/main/java/org/apache/commons/jxpath/ri/axes/ChildContext.java Adding src/test/java/org/apache/commons/jxpath/issues/JXPath113Test.java Transmitting file data ... Committed revision 1716226. Thank you!
        Hide
        Michele Vivoda added a comment - - edited

        Hi Emmanuel Bourg , I did the pull request some time ago but is still there.

        https://github.com/apache/commons-jxpath/pulls

        Show
        Michele Vivoda added a comment - - edited Hi Emmanuel Bourg , I did the pull request some time ago but is still there. https://github.com/apache/commons-jxpath/pulls
        Hide
        Michele Vivoda added a comment -

        Done !

        Show
        Michele Vivoda added a comment - Done !
        Hide
        Emmanuel Bourg added a comment -

        Michele, do you think you could provide a patch with a test case please? If you are used to git you can also fork the repository on Github and send a pull request.

        https://github.com/apache/commons-jxpath

        Show
        Emmanuel Bourg added a comment - Michele, do you think you could provide a patch with a test case please? If you are used to git you can also fork the repository on Github and send a pull request. https://github.com/apache/commons-jxpath
        Hide
        Michele Vivoda added a comment -

        Hi,

        I just compiled JXPath and got back the NPE, code was the same as when bug was opened. After a while I think I sorted it out:

        Patch was applied with a typo, using [parent] instead than [actualParent] / [useParent].

        then Emmanuel Bourg removed the check that was actually useless, revision 652903 and bug is back

        So I would apply the initial proposal, as written in the bug description.

        http://mail-archives.apache.org/mod_mbox/commons-commits/200805.mbox/%3C20080502204633.322742388A08@eris.apache.org%3E

        Show
        Michele Vivoda added a comment - Hi, I just compiled JXPath and got back the NPE, code was the same as when bug was opened. After a while I think I sorted it out: Patch was applied with a typo, using [parent] instead than [actualParent] / [useParent] . then Emmanuel Bourg removed the check that was actually useless, revision 652903 and bug is back So I would apply the initial proposal, as written in the bug description. http://mail-archives.apache.org/mod_mbox/commons-commits/200805.mbox/%3C20080502204633.322742388A08@eris.apache.org%3E
        Hide
        Matt Benson added a comment -

        This one was obvious enough that just a claim of an NPE was good enough. I've committed essentially the fix you've suggested, rev 617893. Thanks!

        Show
        Matt Benson added a comment - This one was obvious enough that just a claim of an NPE was good enough. I've committed essentially the fix you've suggested, rev 617893. Thanks!
        Hide
        Michele Vivoda added a comment -

        Test case:

        XML

        <xml/>

        XPATH

        //following-sibling::node()

        Show
        Michele Vivoda added a comment - Test case: XML <xml/> XPATH //following-sibling::node()

          People

          • Assignee:
            Benedikt Ritter
            Reporter:
            Michele Vivoda
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development