JDK-6717853 : ClassCastException from SynthComboBoxUI in JDK 1.6.0_10 Beta
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u10
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux_ubuntu
  • CPU: x86
  • Submitted: 2008-06-23
  • Updated: 2011-02-22
  • Resolved: 2008-06-27
Related Reports
Duplicate :  
Description
When using NetBeans profiler 6.1 running on JDK 1.6.0_10 Beta on GTK LaF (default for Linux & OpenSolaris), profiling results cannot be displayed and HeapWalker tool doesn't work because of ClassCastException from SynthComboBoxUI. The same happens in VisualVM tool because it shares the NB profiler code.

Issue for tracking this problem on NetBeans side together with more details is at http://www.netbeans.org/issues/show_bug.cgi?id=135812, all bugreports from users are tracked at http://statistics.netbeans.org/analytics/detail.do?id=40178.

The problem is caused by the fact that border of a JComboBox is assigned to a custom JComponent and recent changes in SynthComboBoxUI which assumes that the border is always painted for JComboBox. Sample code is as follows:

 JTextField textField = new JTextField();
 JComboBox comboBox = new JComboBox();
 textField.setBorder(comboBox.getBorder()); // Here's the problem

Running sample code on GTK using JDK 1.6.0_10 Beta causes the following exception to be thrown:

 Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JTextField cannot be cast to javax.swing.JComboBox
        at javax.swing.plaf.synth.SynthComboBoxUI.getComponentState(SynthComboBoxUI.java:196)
        at javax.swing.plaf.synth.SynthComboBoxUI.getContext(SynthComboBoxUI.java:183)
        at javax.swing.plaf.synth.SynthBorder.paintBorder(SynthBorder.java:39)
        at javax.swing.JComponent.paintBorder(JComponent.java:922)
        at javax.swing.JComponent.paint(JComponent.java:1028)
        [...]

Steps to reproduce:
 1/ Use Linux or OpenSolaris, JDK 1.6.0_10 Beta
 2/ Download VisualVM tool (https://visualvm.dev.java.net), unzip and start it, verify that it's running with GTK LaF
 3/ Right-click VisualVM application node in the Applications tree, invoke Heap Dump action
 4/ Heap dump opens in HeapWalker tool, switch to Classes view, exception is thrown

Comments
EVALUATION From my point of view, this code JTextField textField = new JTextField(); JComboBox comboBox = new JComboBox(); textField.setBorder(comboBox.getBorder()); // Here's the problem is dubious, a LookAndFeel can create a special border which looks diffently for differnt states of the combobox which is not designed to be set to another component but to be compatible, it is a good idea to add an extra check and elliminate the exception for this case
23-06-2008

SUGGESTED FIX From my point of
23-06-2008