JDK-6717617 : Nimbus L&F: Regression - Using ComboBox border on TextField causes ClassCastException
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u10
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,linux_ubuntu,windows_vista
  • CPU: generic,x86
  • Submitted: 2008-06-21
  • Updated: 2011-02-22
  • Resolved: 2008-06-26
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
6u10 b27Fixed
Related Reports
Duplicate :  
Description
There is a fairly odd use case which isn't entirely understood to be supported, but which was working and is now broken. The idea is that:

JComboBox cb = new JComboBox();
JTextField tf = new JTextField();
tf.setBorder(cb.getBorder());

Ends up throwing a ClassCastException. The problem is that the border on JComboBox under a Synth based look and feel is a SynthBorder, which maintains a reference to the UI that created it (SynthComboBoxUI in this case). When it is time to paint the border, it asks the UI for the Synth state. This ends up calling a private method on SynthComboBoxUI to determine the state. It would be reasonable to assume that such a private method in SynthComboBoxUI would only deal with SynthComboBoxUI's --- but in the above sequence this assumption is violated and a JTextField is passed to the internal SynthComboBoxUI method instead.

The fix is simply to put a class check back into SynthComboBoxUI. A more correct fix in Java 7 would be to fix SynthBorderUI so that if the UI didn't match the UI of the current component, then it wouldn't ask for the synth state (and thus avoid the problem entirely).

Comments
EVALUATION Evaluation is as described in description
21-06-2008