Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
1.3
-
None
-
None
-
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.