#8712 closed defect (fixed)
"Comparison method violates its general contract" when sorting a collection in Java 7
Reported by: | mdk | Owned by: | team |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | Core | Version: | latest |
Keywords: | java7, java8 | Cc: | stoecker |
Description
Simply open the attached file and start Validator. After validation (when moving the mouse ?) these error occurs.
First I found it in Revision 5950, but it is also in the latest version 5958:
Repository Root: http://josm.openstreetmap.de/svn Build-Date: 2013-05-13 01:34:36 Last Changed Author: Don-vip Revision: 5958 Repository UUID: 0c6e7542-c601-0410-84e7-c038aed88b3b URL: http://josm.openstreetmap.de/svn/trunk Last Changed Date: 2013-05-13 03:10:05 +0200 (Mon, 13 May 2013) Last Changed Rev: 5958 Identification: JOSM/1.5 (5958 en) Linux Ubuntu 12.10 Memory Usage: 347 MB / 876 MB (79 MB allocated, but free) Java version: 1.7.0_21, Oracle Corporation, OpenJDK Server VM VM arguments: [-Djosm.home=/home/michael/.josm-latest, -Djava.net.useSystemProxies=true] Dataset consistency test: No problems found Plugin: ColumbusCSV (29500) Plugin: FastDraw (29532) Plugin: HouseNumberTaggingTool (29487) Plugin: OpeningHoursEditor (29435) Plugin: RoadSigns (29435) Plugin: SimplifyArea (29435) Plugin: buildings_tools (29435) Plugin: contourmerge (1003) Plugin: imagery_offset_db (29467) Plugin: multipoly-convert (29435) Plugin: poly (29435) Plugin: public_transport (29435) Plugin: reltoolbox (29535) Plugin: reverter (29561) Plugin: terracer (29509) Plugin: turnrestrictions (29435) Plugin: utilsplugin2 (29435) 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 javax.swing.SortingFocusTraversalPolicy.enumerateAndSortCycle(SortingFocusTraversalPolicy.java:136) at javax.swing.SortingFocusTraversalPolicy.getFocusTraversalCycle(SortingFocusTraversalPolicy.java:110) at javax.swing.SortingFocusTraversalPolicy.getComponentAfter(SortingFocusTraversalPolicy.java:280) at javax.swing.LayoutFocusTraversalPolicy.getComponentAfter(LayoutFocusTraversalPolicy.java:106) at java.awt.Component.getNextFocusCandidate(Component.java:7860) at java.awt.Component.transferFocus(Component.java:7828) at java.awt.Component.hide(Component.java:1684) at java.awt.Component.show(Component.java:1653) at java.awt.Component.setVisible(Component.java:1603) at javax.swing.JComponent.setVisible(JComponent.java:2631) at org.openstreetmap.josm.gui.dialogs.ToggleDialog.eventDispatched(ToggleDialog.java:875) at java.awt.Toolkit$SelectiveAWTEventListener.eventDispatched(Toolkit.java:2434) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2326) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2325) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2325) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2325) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2325) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2325) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2325) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2325) at java.awt.Toolkit.notifyAWTEventListeners(Toolkit.java:2284) at java.awt.Component.dispatchEventImpl(Component.java:4757) at java.awt.Container.dispatchEventImpl(Container.java:2287) at java.awt.Component.dispatchEvent(Component.java:4687) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4505) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422) at java.awt.Container.dispatchEventImpl(Container.java:2273) at java.awt.Window.dispatchEventImpl(Window.java:2719) at java.awt.Component.dispatchEvent(Component.java:4687) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729) at java.awt.EventQueue.access$200(EventQueue.java:103) at java.awt.EventQueue$3.run(EventQueue.java:688) at java.awt.EventQueue$3.run(EventQueue.java:686) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87) at java.awt.EventQueue$4.run(EventQueue.java:702) at java.awt.EventQueue$4.run(EventQueue.java:700) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:699) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Attachments (1)
Change History (10)
by , 12 years ago
comment:2 by , 12 years ago
Fix targeted to Java 8: javabug:7075600
Funny thing, Oracle almost fixed the bug in 7u6 before changing their mind (sic): javabug:2217231
comment:3 by , 12 years ago
Keywords: | java7 java8 added |
---|
Described here: http://www.oracle.com/technetwork/java/javase/compatibility-417013.html#jdk7
Area: API: Utilities
Synopsis: Updated sort behavior for Arrays and Collections may throw anIllegalArgumentException
Description: The sorting algorithm used byjava.util.Arrays.sort
and (indirectly) byjava.util.Collections.sort
has been replaced. The new sort implementation may throw anIllegalArgumentException
if it detects aComparable
that violates theComparable
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.
Nature of Incompatibility: behavioral
RFE: 6804124
comment:4 by , 12 years ago
comment:5 by , 12 years ago
Cc: | added |
---|
@mdk: you're right, the second one is exact duplicate. Other ones must be fixed on our side.
I'd be tempted to apply the workaround (setting system property java.util.Arrays.useLegacyMergeSort
to true
until we switch to Java 8 in many years), but not by default for local builds, because it will hide some bogus Comparators to developers too (like those that we must fix in #8335 and #8671).
So something like this:
if (Main.pref.getBoolean("jdk.Arrays.useLegacyMergeSort", !Version.getInstance().isLocalBuild())) { System.setProperty("java.util.Arrays.useLegacyMergeSort", true); }
Dirk, your opinion about this ?
comment:6 by , 12 years ago
Summary: | Error after validating changes → "Comparison method violates its general contract" when sorting a collection in Java 7 |
---|
comment:7 by , 12 years ago
Dirk, your opinion about this?
I can't see the java bug reports ălways telling me "This bug is not available.", but it sounds like a proper solution to me.
Data to validate