Commons JXPath
  1. Commons JXPath
  2. JXPATH-133

Cloning the node pointers and '==' node pointers comparison

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3
    • Fix Version/s: None
    • Labels:
      None
    • Environment:

      JDK 1.5.0_12, JBoss 4.0.5

      Description

      During the implementation of JCR nodes support in JXPath (extending NodePonter's, NodeIterator's, NodePointerFactory ) I faced with the following situation: I was running a xpath query against the context (JXPathContext instance) like:

      context.iteratePointers("/child::* | @ * ")

      After that I got an exception JXPathException: "Cannot compare pointers that do not belong to the same tree: '/home' and '/home' " thrown from NodePointer.compareNodePointers(...) method. After debugging this case I've found that for the node pointers extracted via the "/child::* | @ * " xpath expression NodePointer.compareTo(Object) was invoked (and consequently NodePointer.compareNodePointers(...) ). In fact all node pointers matching the "/child::* | @ * " xpath expression had the same node pointer (I checked it against my implementations of NodePointerFactory, NodeIterator's etc.). But as I found for these node pointers they were initialized with different clones of the same parent node pointer. And the result was that in NodePointer.compareTo(Object) method the following "==" comparison evaluated in false for the different clones of the same parent node pointer:

      if (parent == pointer.parent)

      { return parent == null ? 0 : parent.compareChildNodePointers(this, pointer); }

      As the workaround for this case I overrode the clone method for my NodePointer descendants to return 'this'. I think there is some misbalance made between the usage of clone () method of NodePointer's and "==" comparison of NodePointers.

        Activity

        Hide
        Matt Benson added a comment -

        As you can see elsewhere in NodePointer, that comparison should be done using == || .equals; I have added this in compareTo() as you suggest in revision 918156. Thanks!

        Show
        Matt Benson added a comment - As you can see elsewhere in NodePointer, that comparison should be done using == || .equals; I have added this in compareTo() as you suggest in revision 918156. Thanks!

          People

          • Assignee:
            Unassigned
            Reporter:
            Vladimir Orlov
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development