Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8002072

LayoutComparator.compare throws ClassCastException exception when there is a <null> component

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • 8
    • 7u6
    • client-libs


      JAVA VERSION:
         1.7.0_07 32bit Oracle Corporation

      OS VERSION :
      Linux 2.6.33.3-mac i386 (but issue is os independent)

      A DESCRIPTION OF THE PROBLEM :

      this is a bug in "javax.swing.LayoutComparator.compare". At least the code in there is not fail safe.

      The API method called is "java.awt.Windows.isFocusableWindow()", where nothing is stated about thread safety or restriction to be called in EDT. There is a raise condition:

      * all child components of the window are enumerated in a list
      * when sorting this list there is a <null> component or a component which isn't in any window hierarchy

      In this case " javax.swing.LayoutComparator.compare" throws a ClassCastException, which is inanely hilarious. <null> or components not 'on' the window should be sorted just to the last position.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a window with many components, listeners, etc. and call "isFocusableWindow" on it.
      Start VM with jdk.map.althashing.threshold to 0.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No ClassCastException
      ACTUAL -
      java.lang.ClassCastException


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      JDK=1.7.0_07 32bit Oracle Corporation;OS=Linux
      2.6.33.3-mac i386;Date=30.10.2012 15:35:27
      java.lang.ClassCastException
      at javax.swing.LayoutComparator.compare(LayoutComparator.java:75)
      at javax.swing.LayoutComparator.compare(LayoutComparator.java:42)
      at java.util.TimSort.countRunAndMakeAscending(TimSort.java:329)
      at java.util.TimSort.sort(TimSort.java:189)
      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.getFirstComponent(SortingFocusTraversalPolicy.java:435)
      at
      javax.swing.LayoutFocusTraversalPolicy.getFirstComponent(LayoutFocusTraversalPolicy.java:166)
      at
      javax.swing.SortingFocusTraversalPolicy.getDefaultComponent(SortingFocusTraversalPolicy.java:515)
      at java.awt.Window.isFocusableWindow(Window.java:2476)


      REPRODUCIBILITY :
      This bug can be reproduced occasionally.

      CUSTOMER SUBMITTED WORKAROUND :
      disable tim sort




            alexsch Alexandr Scherbatiy
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: