我正在尝试对我的用户分数进行排序。它在本地运行良好,但是当我查看服务器日志时,它会引发很多异常。所以我尝试空检查并捕获异常,但异常仍然抛出异常。我不确定有什么例外。
Collections.sort(userScores, new Comparator<UserScore>() {
@Override
public int compare(UserScore o1, UserScore o2) {
try {
if(o1 == null || o1.getScore() == null) {
return 1;
}
if(o2 == null || o2.getScore() == null) {
return -1;
}
if(o1.getScore().doubleValue() > o2.getScore().doubleValue())
return -1;
return 1;
}catch(Exception ex) {
logger.severe(ex.getMessage());
return 0;
}
}
});
我的代码抛出,
java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.TimSort.mergeLo(TimSort.java:777) ~[na:1.8.0_181]
at java.util.TimSort.mergeAt(TimSort.java:514) ~[na:1.8.0_181]
at java.util.TimSort.mergeCollapse(TimSort.java:441) ~[na:1.8.0_181]
at java.util.TimSort.sort(TimSort.java:245) ~[na:1.8.0_181]
at java.util.Arrays.sort(Arrays.java:1438) ~[na:1.8.0_181]
at java.util.List.sort(List.java:478) ~[na:1.8.0_181]
at java.util.Collections.sort(Collections.java:175) ~[na:1.8.0_181]
at com.tll.treeofwords.game.service.GameService.generateRanking(GameService.java:179) ~[classes!/:0.0.1-SNAPSHOT]
at com.tll.treeofwords.game.service.GameService.getCurrentGame(GameService.java:76) ~[classes!/:0.0.1-SNAPSHOT]
at com.tll.treeofwords.game.service.GameService.getCurrentGame(GameService.java:59) ~[classes!/:0.0.1-SNAPSHOT]
at com.tll.treeofwords.game.service.GameService$$FastClassBySpringCGLIB$$d5f3b9ef.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
叮当猫咪
浮云间
相关分类