关闭

java错误Comparison method violates its general contract!

标签: java异常
473人阅读 评论(0) 收藏 举报
分类:

今天用到Collections.sort();方法时,提示错误如下:


网上查到一个解释:

Description: The sorting algorithm used by java.util.Arrays.sort and (indirectly) by java.util.Collections.sort has been replaced. The new sort implementation may throw an IllegalArgumentException if it detects a Comparable that violates the Comparable contract. The previous implementation silently ignored such a situation. If the previous behavior is desired, you can use the new system property, java.util.Arrays.useLegacyMergeSort, to restore previous mergesort behavior.

也就是说jdk 7的sort函数的实现变了,造成了这个问题,具体原因未知。

网上找了解决方法,如下

加入一句代码

<span style="font-size:14px;">System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");</span>

转载出处:http://blog.csdn.net/fanzitao/article/details/8040201

0
0
查看评论

Comparison method violates its general contract!

背景16号为了统一线上服务器运行环境,将两台服务器的Tomcat6+JDK6升级到Tomcat7+JDK7,本以为很简单的事情,升级后自己验证也没问题,没想到却悲剧了。升级后,过了半小时运营就找过来反馈问题,部分角色无法登陆系统,由于异常日志没有输出,没有找到问题,无奈回滚。今天我们就来说说JDK6...
  • ghsau
  • ghsau
  • 2014-12-18 23:08
  • 32713

关于JDK7的IllegalArgumentException:Comparison method violates its general contract

关于JDK7的IllegalArgumentException:Comparison method violates its general contract今天看社区问答的时候看到的一个问题,起因是说阿里开发手册中关于Compartor的实现的问题,建议实现满足对称性,传递性和自反性.回答中提到了...
  • lqadam
  • lqadam
  • 2017-05-30 15:43
  • 722

IllegalArgumentException: Comparison method violates its general contract错误详细内容

今天在开发的过程中出现了一个比较诡异的报错。 截取部分报错信息 java.lang.IllegalArgumentException: Comparison method violates its general contract! at java.util.TimSort.mergeLo(Tim...
  • jerry1744110
  • jerry1744110
  • 2014-12-08 12:45
  • 743

这个坑,你要注意:Comparison method violates its general contract!

背景有部分业务需要进行排序,对比的对象是某实体里的金额(double 类型),这样,我们实现了自定义的比较类,结果运行一段时间之后报了错误:Comparison method violates its general contract! ,经过校验,发现错误出现在自定义排序上,经网上各种查阅资料发现...
  • xvshu
  • xvshu
  • 2017-04-13 09:30
  • 3708

Android碰到 "Comparison method violates its general contract" 异常的解决方法

1.概述:  最近在对信息进行排序时,做了一个简单地比较器,当时在运行时并没有报错,但是,后台数据刷新时,我这边就出了问题。在jdk1.6中,当我们比较的内容的值相同时,使用java自己的排序方法"Collections.sort()"是很正常的,可是到了jdk1...
  • yanxiaosa
  • yanxiaosa
  • 2016-09-20 13:41
  • 2216

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

异常信息 java.lang.IllegalArgumentException: Comparison method violates its general contract! at java.util.TimSort.mergeLo(TimSort.java:747) at java.util....
  • love_world_
  • love_world_
  • 2016-05-06 16:44
  • 4193

java、scala集合自定义排序异常:Comparison method violates its general contract!

cala 集合(array,seq)排序报错 User class threw exception: org.apache.spark.SparkException: Job aborted due to stage failure: Task 43 in stage 3.0 failed 4 t...
  • a822631129
  • a822631129
  • 2017-05-11 15:23
  • 1085

Java 错误解决之java.lang.IllegalArgumentException: Comparison method violates its general contract

在jdk1.7上使用分类排序会报下面错误 java.lang.IllegalArgumentException: Comparison method violates its general contract! at java.util.TimSort.mergeLo(TimSort.ja...
  • u011324501
  • u011324501
  • 2017-06-21 19:16
  • 482

java.lang.IllegalArgumentException: Comparison method violates its general contract!的解决方法

上午在敲代码时,对一个List集合进行排序,代码如下:          Collections.sort(list2,new Comparator() { @Override public ...
  • u010198383
  • u010198383
  • 2015-07-01 14:06
  • 252

java 集合排序异常Exception in thread "main" java.lang.IllegalArgumentException: Comparison method violate

报错 Exception in thread "main" java.lang.IllegalArgumentException: Comparison method violates its general contract! 原因在于比较的值中有NaN,所以不...
  • a7760764
  • a7760764
  • 2016-11-22 22:40
  • 190
    个人资料
    • 访问:269511次
    • 积分:3116
    • 等级:
    • 排名:第13196名
    • 原创:89篇
    • 转载:55篇
    • 译文:0篇
    • 评论:39条