Comparison Method violates its general contract

Source: Internet
Author: User

 

Check for errors in the production environment. The error log is as follows:

java.lang.IllegalArgumentException: Comparison method violates its general contract!at java.util.TimSort.mergeLo(TimSort.java:747) ~[na:1.7.0_40]at java.util.TimSort.mergeAt(TimSort.java:483) ~[na:1.7.0_40]at java.util.TimSort.mergeCollapse(TimSort.java:408) ~[na:1.7.0_40]at java.util.TimSort.sort(TimSort.java:214) ~[na:1.7.0_40]at java.util.TimSort.sort(TimSort.java:173) ~[na:1.7.0_40]at java.util.Arrays.sort(Arrays.java:659) ~[na:1.7.0_40]at java.util.Collections.sort(Collections.java:217) ~[na:1.7.0_40]

The problem occurs intermittently in the production environment. It is good in the local development environment. I searched the internet for this error and found that there were still many people. The specific cause is the new timesort Sorting Algorithm of JDK 7. For details, refer to this blog post:

Http://www.lifebackup.cn/timsort-java7.html

Summary: The comparison logic of the comparator must be correct and equal conditions must be put back, that is, 0. Note that the comparison of the reference type needs to be converted to a simple type for comparison.

 

Comparison Method violates its general contract

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.