Details
Description
The following exception is thrown from the DOMXPath.selectNodes(node) with jdk7:-
DOMXPath xpath = new DOMXPath("xPath Expression");
nodeList = xpath.selectNodes(node);
Exception:-
Caused by: java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.TimSort.mergeLo(TimSort.java:747)
at java.util.TimSort.mergeAt(TimSort.java:483)
at java.util.TimSort.mergeForceCollapse(TimSort.java:426)
at java.util.TimSort.sort(TimSort.java:223)
at java.util.TimSort.sort(TimSort.java:173)
at java.util.Arrays.sort(Arrays.java:659)
at java.util.Collections.sort(Collections.java:217)
at org.jaxen.expr.DefaultUnionExpr.evaluate(DefaultUnionExpr.java:116)
at org.jaxen.expr.DefaultFilterExpr.evaluate(DefaultFilterExpr.java:168)
at org.jaxen.expr.DefaultXPathExpr.asList(DefaultXPathExpr.java:102)
at org.jaxen.BaseXPath.selectNodesForContext(BaseXPath.java:674)
at org.jaxen.BaseXPath.selectNodes(BaseXPath.java:213)
The issue is not seen with jdk6.
It think the issue is that n JDK 7 the "Arrays.sort" has changed to use a new sorting algorithm TimSort, which is more stringent about the comparison function.
See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7075600
This is probably just a manifestation of
JAXEN-215: The NodeComparator is broken, and does not conform to the Comparator's contract.NodeComparator does not return 0 in all instances of a == b.
NodeComparator in some instances returns compare(a,b) == compare(b,a) != 0
Rolf