Here is the stack trace I am getting
Caused by: java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.TimSort.mergeLo(TimSort.java:777)
at java.util.TimSort.mergeAt(TimSort.java:514)
at java.util.TimSort.mergeCollapse(TimSort.java:441)
at java.util.TimSort.sort(TimSort.java:245)
at java.util.Arrays.sort(Arrays.java:1512)
at java.util.ArrayList.sort(ArrayList.java:1454)
at java.util.Collections.sort(Collections.java:175)
at xxx.sortDisplayFields(OfferFieldLayout.java:521)
Here is the compare method:
public int compare(Field pObject1, Field pObject2)
{
int compare = 0;
//...
if (compare == 0)
{
if (pObject1.hashCode() <= pObject2.hashCode())
{
compare = -1;
}
else
{
compare = 1;
}
}
return compare;
}
I think this is due to the transitive property not being respected : transitivity: if A > B and B > C then for any A, B and C: A > C. I am trying to come up with a counter example but I am failing here, any help appreciated!