Modify

Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#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)

temp.osm (1.1 MB) - added by mdk 8 years ago.
Data to validate

Download all attachments as: .zip

Change History (10)

Changed 8 years ago by mdk

Attachment: temp.osm added

Data to validate

comment:1 Changed 8 years ago by Don-vip

Seems to be this Java bug, introduced in JDK7: javabug:6923200

Last edited 7 years ago by Don-vip (previous) (diff)

comment:2 Changed 8 years ago by Don-vip

Fix targeted to Java 8: javabug:7075600

Funny thing, Oracle almost fixed the bug in 7u6 before changing their mind (sic): javabug:2217231

Last edited 7 years ago by Don-vip (previous) (diff)

comment:3 Changed 8 years ago by Don-vip

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 an IllegalArgumentException
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.
Nature of Incompatibility: behavioral
RFE: 6804124

comment:4 Changed 8 years ago by mdk

There are some other tickets, which seems to be related: #8335, #8453 and #8671

comment:5 Changed 8 years ago by Don-vip

Cc: stoecker 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 Changed 8 years ago by Don-vip

Summary: Error after validating changes"Comparison method violates its general contract" when sorting a collection in Java 7

comment:7 Changed 8 years ago by stoecker

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.

comment:8 Changed 8 years ago by Don-vip

Sun bug tracker is live again if you want to look at the bugs first :)

comment:9 Changed 8 years ago by Don-vip

Resolution: fixed
Status: newclosed

In 5977/josm:

fix #8712 - workaround to "Comparison method violates its general contract" when sorting a collection in Java 7, disabled for local builds. Set new property jdk.Arrays.useLegacyMergeSort to true to enable the workaround for local builds.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.