JDK-6434148 : ClassCastException thrown while running SwingSet2 demo
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P1
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows
  • CPU: x86
  • Submitted: 2006-06-05
  • Updated: 2010-04-03
  • Resolved: 2006-06-07
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 6
6 b87Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
On Win32 XP machine.

Install June 5th 2006 master nightly build, running swingset2 demo:

java -jar SwingSet2.jar

Under "Look & Feel" menu, switch to windows look and feel, you will get exception:

(mustang b86 promoted build is okay)

Failed loading L&F: com.sun.java.swing.plaf.windows.WindowsLookAndFeel
java.lang.ClassCastException: javax.swing.KeyStroke cannot be cast to java.lang.
Comparable
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing
.plaf.ColorUIResource cannot be cast to java.util.List
        at javax.swing.plaf.metal.MetalUtils.drawGradient(Unknown Source)
        at javax.swing.plaf.metal.MetalInternalFrameTitlePane.paintComponent(Unk
nown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JLayeredPane.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JLayeredPane.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintToOffscreen(Unknown Source)
        at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
        at javax.swing.RepaintManager.paint(Unknown Source)
        at javax.swing.JComponent._paintImmediately(Unknown Source)
        at javax.swing.JComponent.paintImmediately(Unknown Source)
        at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
        at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
        at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknow
n Source)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing
.KeyStroke cannot be cast to java.lang.Comparable
        at java.util.TreeMap.compare(Unknown Source)
        at java.util.TreeMap.put(Unknown Source)
        at java.util.TreeSet.add(Unknown Source)
        at com.sun.java.swing.plaf.windows.WindowsTabbedPaneUI.installDefaults(U
nknown Source)
        at javax.swing.plaf.basic.BasicTabbedPaneUI.installUI(Unknown Source)
        at javax.swing.JComponent.setUI(Unknown Source)
        at javax.swing.JTabbedPane.setUI(Unknown Source)
        at javax.swing.JTabbedPane.updateUI(Unknown Source)
        at javax.swing.SwingUtilities.updateComponentTreeUI0(Unknown Source)
        at javax.swing.SwingUtilities.updateComponentTreeUI0(Unknown Source)
        at javax.swing.SwingUtilities.updateComponentTreeUI(Unknown Source)
        at SwingSet2$6.run(SwingSet2.java:973)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)


You cannot start java control panel also, because of the same problem:

Exception in thread "main" java.lang.ClassCastException: javax.swing.KeyStroke c
annot be cast to java.lang.Comparable
        at java.util.TreeMap.compare(Unknown Source)
        at java.util.TreeMap.put(Unknown Source)
        at java.util.TreeSet.add(Unknown Source)
        at com.sun.java.swing.plaf.windows.WindowsTabbedPaneUI.installDefaults(U
nknown Source)
        at javax.swing.plaf.basic.BasicTabbedPaneUI.installUI(Unknown Source)
        at javax.swing.JComponent.setUI(Unknown Source)
        at javax.swing.JTabbedPane.setUI(Unknown Source)
        at javax.swing.JTabbedPane.updateUI(Unknown Source)
        at javax.swing.JTabbedPane.<init>(Unknown Source)
        at javax.swing.JTabbedPane.<init>(Unknown Source)
        at com.sun.deploy.panel.ControlPanel.initComponents(Unknown Source)
        at com.sun.deploy.panel.ControlPanel.<init>(Unknown Source)
        at com.sun.deploy.panel.ControlPanel.main(Unknown Source)

Comments
EVALUATION I found the following references ot TreeSet in javax.swing and com.sun.java.swing.plaf: 1) ./JDesktopPane.java(26): import java.util.TreeSet; ./JDesktopPane.java(329): Set<ComponentPosition> set = new TreeSet<ComponentPosition>(); ComponentPosition implements Comparable, so we're okay here. 2) ./JTextArea.java(18): import java.util.TreeSet; TreeSet actually goes unused in JTextArea.java, so this import line can be removed. 3) ./plaf/basic/BasicSplitPaneUI.java(356): managingFocusForwardTraversalKeys = new TreeSet(); ./plaf/basic/BasicSplitPaneUI.java(364): managingFocusBackwardTraversalKeys = new TreeSet(); ./plaf/synth/SynthSplitPaneUI.java(82): managingFocusForwardTraversalKeys = new TreeSet(); ./plaf/synth/SynthSplitPaneUI.java(90): managingFocusBackwardTraversalKeys = new TreeSet(); ./windows/WindowsTabbedPaneUI.java(16): import java.util.TreeSet; ./windows/WindowsTabbedPaneUI.java(54): managingFocusForwardTraversalKeys = new TreeSet(); ./windows/WindowsTabbedPaneUI.java(60): managingFocusBackwardTraversalKeys = new TreeSet(); The same problem occurs in these three UI classes. A TreeSet is used for storing KeyStrokes, but the KeyStroke class does not implement Comparable. The TreeSets are then passed into setFocusTraversalKeys(). Component.setFocusTraversalKeys() makes no mention of requiring a SortedSet. Changing to use a HashSet instead ought to fix things up nicely.
06-06-2006

EVALUATION This bug results from an incorrect usage of TreeSet by Swing. The TreeSet documentation for the empty constructor says that all objects used with it must implement Comparable. Swing has multiple places (I suggest a grep for TreeSet) that don't follow this constraint. It appears that we've been lucky until now, when a change in TreeSet has revealed our error. Suggested fix is to replace bad usages of TreeSet with HashSet.
06-06-2006