JDK-8055750 : problem with LayoutComparator / SortingFocusTraversalPolicy
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7,8,9
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2012-06-14
  • Updated: 2015-03-03
  • Resolved: 2015-03-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Resolved
Related Reports
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b22)
Java HotSpot(TM) Client VM (build 23.0-b21, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows XP

EXTRA RELEVANT SYSTEM CONFIGURATION :
Happens in standalone as well as when invoking java program in JNLP mode.


A DESCRIPTION OF THE PROBLEM :
This issue is same as described in bug 6923200 which seems to be closed but I am seeing this consistently using latest JRE 7

1. while disabling a button on  a panel which is inside JTabbed pane. It seems to cause this following exception consistently while using JRE 7  1.7.0_04-b22

java.lang.IllegalArgumentException: Comparison method violates its general contract!
        at java.util.TimSort.mergeHi(TimSort.java:868)
        at java.util.TimSort.mergeAt(TimSort.java:485)
        at java.util.TimSort.mergeForceCollapse(TimSort.java:426)
        at java.util.TimSort.sort(TimSort.java:223)
        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.disable(Component.java:1517)
        at javax.swing.JComponent.disable(JComponent.java:3635)
        at java.awt.Component.enable(Component.java:1495)
        at java.awt.Component.setEnabled(Component.java:1458)
        at javax.swing.JComponent.setEnabled(JComponent.java:2677)
        at javax.swing.AbstractButton.setEnabled(AbstractButton.java:2087)


============================================================




2. while removing all and adding new components:


============================================================
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException:
Comparison method violates its general contract!
	at java.util.TimSort.mergeHi(Unknown Source)
	at java.util.TimSort.mergeAt(Unknown Source)
	at java.util.TimSort.mergeForceCollapse(Unknown Source)
	at java.util.TimSort.sort(Unknown Source)
	at java.util.TimSort.sort(Unknown Source)
	at java.util.Arrays.sort(Unknown Source)
	at java.util.Collections.sort(Unknown Source)
	at javax.swing.SortingFocusTraversalPolicy.enumerateAndSortCycle(Unknown
Source)
	at
javax.swing.SortingFocusTraversalPolicy.getFocusTraversalCycle(Unknown Source)
	at javax.swing.SortingFocusTraversalPolicy.getComponentAfter(Unknown
Source)
	at javax.swing.LayoutFocusTraversalPolicy.getComponentAfter(Unknown
Source)
	at java.awt.Component.getNextFocusCandidate(Unknown Source)
	at java.awt.Component.transferFocus(Unknown Source)
	at java.awt.Container.removeNotify(Unknown Source)
	at javax.swing.JComponent.removeNotify(Unknown Source)
	at java.awt.Container.removeAll(Unknown Source)
=======================================================


These errors are happening randomly making it hard to use this app with JRE 7.

REGRESSION.  Last worked in version 7

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I have a java swing app with JFrame,  which has a tabbed pane .
each pane has JSplitPane ,  with right side of split pane child has several panels inside.
Each panel has several buttons and JTable inside jscrollpane

button actions usually disables itself takes some action and then it is enabled again.  When enabling button exceptions mentioned in description happens.

Also some button actions result in panel be cleared of existing panels inside it and new panels being displayed. In this case  second exception mentioned in description item 2 happens sometimes.



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
expected result:
 code should proceed without any of exceptions mentioned.
ACTUAL -
Exception happens at random place of enable/disable.
It is not possible to even have try catch and ignore this.  Button actions don't happen properly.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.IllegalArgumentException: Comparison method violates its general contract!

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
None.

Comments
The issue is fixed already somehow. It can be reproduced in 1.7.0_04 but is not reproducable in the latest versions of 7, 8 and 9.
24-02-2015

Workaround: Set "java.util.Arrays.useLegacyMergeSort" to true, either on the command line or in main: System.setProperty("java.util.Arrays.useLegacyMergeSort", "true"); If this property is set, the app starts successfully.
21-08-2014

Use BrokenLayoutComparator.java from JI-9001396 to reproduce.
21-08-2014