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

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        221d 6h 57m 1 Matt Benson 02/Mar/10 19:20
        Matt Benson made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        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!
        Vladimir Orlov made changes -
        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.
        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.
        Vladimir Orlov made changes -
        Field Original Value New Value
        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.
        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.
        Vladimir Orlov created issue -

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development