惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
Cisco Talos Blog
Cisco Talos Blog
C
Check Point Blog
博客园_首页
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Martin Fowler
Martin Fowler
Recorded Future
Recorded Future
S
Security @ Cisco Blogs
L
LINUX DO - 最新话题
博客园 - 司徒正美
P
Privacy International News Feed
G
Google Developers Blog
I
Intezer
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Scott Helme
Scott Helme
K
Kaspersky official blog
I
InfoQ
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Webroot Blog
Webroot Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
大猫的无限游戏
大猫的无限游戏
D
Docker
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
Microsoft Azure Blog
Microsoft Azure Blog
Spread Privacy
Spread Privacy
量子位
H
Hacker News: Front Page
Simon Willison's Weblog
Simon Willison's Weblog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
SecWiki News
SecWiki News
S
Security Affairs
Latest news
Latest news
人人都是产品经理
人人都是产品经理
C
CERT Recently Published Vulnerability Notes
S
Security Archives - TechRepublic
V
Visual Studio Blog
T
Troy Hunt's Blog
S
Secure Thoughts
F
Fortinet All Blogs
V
V2EX
The Register - Security
The Register - Security
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO

博客园 - 天纯蓝

go错误总结(27条) GO语言最主的特性 Centos7 Mysql5.7主从服务器配置 maven buid 导出项目依赖的jar包问题 [数据库]漫谈ElasticSearch关于ES性能调优几件必须知道的事(转) MongoDB 聚合管道(Aggregation Pipeline) mongodb分布式查询 MongoDB JAVA API Filters mongodb.conf配置文件详解 mongodb安装配置 Elasticsearch-2.3.x填坑之路 CentOS VMware 下SSH配置方法详解 15个nosql数据库 MySql 优化 Elasticsearch 相关名词理解 - 天纯蓝 Elasticsearch集群中处理大型日志流的几个常用概念 - 天纯蓝 ES配置文件参考与参数详解 - 天纯蓝 Java连接Elasticsearch集群 Linux下Tomcat的启动、关闭、杀死进程
解决“Comparison method violates its general contract!”
天纯蓝 · 2017-12-22 · via 博客园 - 天纯蓝

The ONE跑MaxProp、Prophet可能(取决于你JDK的版本)会报“java.lang.IllegalArgumentException: Comparison method violates its general contract!”错误,导致无法仿真。

Exception in thread "main" 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.mergeCollapse(TimSort.java:410)
at java.util.TimSort.sort(TimSort.java:214)
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 routing.MaxPropRouter.tryOtherMessages(MaxPropRouter.java:385)
at routing.MaxPropRouter.update(MaxPropRouter.java:300)
at core.DTNHost.update(DTNHost.java:342)
at core.World.updateHosts(World.java:200)
at core.World.update(World.java:171)
at ui.DTNSimTextUI.runSim(DTNSimTextUI.java:29)
at ui.DTNSimUI.start(DTNSimUI.java:77)
at core.DTNSim.main(DTNSim.java:170)


2. 问题原因
产生该问题的原因是JDK1.6+要求所有比较器必须是可传递的(transitive),比如有A > B 和B > C,必须得保证有推出A > C(同理,对于=和<也需满足传递性)。而The ONE源码是基于JDK1.6的,JDK1.6没有该要求。

3. 解决方法
解决该问题至少有3种方法。

(1)使用JDK1.6版本运行

(2)修改The ONE源码,使其满足传递性

只需要更改Router的比较器Comparator就可以了,比如MaxProp的MaxPropComparator:

private class MaxPropComparator implements Comparator<Message> {
...
}
(3)重新编译源码

加上一些选项,重新编译The ONE源码,使其能在JDK1.6+能正常运行[1]。

方法一:在main函数第一行加入如下代码:

System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
方法2:编译时,加上选项-Djava.util.Arrays.useLegacyMergeSort=true,完整Java编译如下:

java -Djava.util.Arrays.useLegacyMergeSort=true -d64 -Xms512m -Xmx4g -cp .:lib/ECLA.jar:lib/DTNConsoleConnection.jar core.DTNSim $*

参考资料:
https://stackoverflow.com/questions/13575224/comparison-method-violates-its-general-contract-timsort-and-gridlayout