java.lang.IllegalArgumentException: Comparison method violates its general contract!

We are seeing the following error message:
17:21:17,649 ERROR [org.jboss.stdio.AbstractLoggingWriter.write(AbstractLoggingWriter.java:71)] (ajp-/172.16.1.42:8109-5) java.lang.IllegalArgumentException: Comparison method violates its general contract!
17:21:17,650 ERROR [org.jboss.stdio.AbstractLoggingWriter.write(AbstractLoggingWriter.java:71)] (ajp-/172.16.1.42:8109-5) at java.util.ComparableTimSort.mergeLo(ComparableTimSort.java:714)

Resolution

This is the error description:
java.lang.IllegalArgumentException: Comparison method violates its general contract!

And this appears to be the location:
at java.util.ComparableTimSort.mergeLo(ComparableTimSort.java:714)

You have a compare() method in this ComparableTimSort class which implements the Comparator interface (https://docs.oracle.com/javase/7/docs/api/java/util/Comparator.html).

See this article for more information on your error:
http://stackoverflow.com/questions/7849539/comparison-method-violates-its-general-contract-java-7-only

Something about the object you are passing to the compare() method is incorrect, most commonly it may be returning a bad value like null or NaN, or it may be violating the behavioral contract about how compare() should relate to equal().

This message is a new behavior in Java 7, in older versions the error was silently ignored. You can work around it and get the old behavior back by using this JVM command line property:
-Djava.util.Arrays.useLegacyMergeSort=true

However, it is preferable to fix the offending code if possible.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.