commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matt Benson (JIRA)" <>
Subject [jira] Commented: (JXPATH-133) Cloning the node pointers and '==' node pointers comparison
Date Tue, 02 Mar 2010 19:21:27 GMT


Matt Benson commented on JXPATH-133:

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!

> Cloning the node pointers and '==' node pointers comparison
> -----------------------------------------------------------
>                 Key: JXPATH-133
>                 URL:
>             Project: Commons JXPath
>          Issue Type: Bug
>    Affects Versions: 1.3
>         Environment: JDK 1.5.0_12, JBoss 4.0.5
>            Reporter: Vladimir Orlov
> 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.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message