United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-8055750 : problem with LayoutComparator / SortingFocusTraversalPolicy

Details
Type:
Bug
Submit Date:
2012-06-14
Status:
Closed
Updated Date:
2015-03-03
Project Name:
JDK
Resolved Date:
2015-03-03
Component:
client-libs
OS:
windows_xp
Sub-Component:
javax.swing
CPU:
x86
Priority:
P3
Resolution:
Not an Issue
Affected Versions:
7,8,9
Fixed Versions:
9

Related Reports
Relates:
Relates:
Relates:

Sub Tasks

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.

                                     
2015-02-24
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.
                                     
2014-08-21
Use BrokenLayoutComparator.java from JI-9001396 to reproduce.
                                     
2014-08-21



Hardware and Software, Engineered to Work Together