JDK-6318663 : Reg. WToolkit. All swing components throw ClassCastException in headless mode
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-09-01
  • Updated: 2012-03-23
  • Resolved: 2005-09-19
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 b53Fixed
Related Reports
Relates :  
Description
This is reproducible on Windows platform from mustang b47. All swing components throw ClassCastException in their constructor in headless mode.

The exception stack trace:

Exception in thread "main" java.lang.ExceptionInInitializerError
        at javax.swing.JButton.updateUI(JButton.java:113)
        at javax.swing.AbstractButton.init(AbstractButton.java:2017)
        at javax.swing.JButton.<init>(JButton.java:103)
        at javax.swing.JButton.<init>(JButton.java:76)
        at HeadlessTest.main(HeadlessTest.java:7)
Caused by: java.lang.ClassCastException: sun.awt.HeadlessToolkit cannot be cast to sun.awt.SunToolkit
        at sun.awt.SunToolkit.getDesktopFontHints(SunToolkit.java:1452)
        at sun.awt.windows.WDesktopProperties.setDesktopAAHints(WDesktopProperties.java:283)
        at sun.awt.windows.WToolkit.initializeDesktopProperties(WToolkit.java:904)
        at java.awt.Toolkit.getDesktopProperty(Toolkit.java:1657)
        at java.awt.Toolkit.getDesktopProperty(Toolkit.java:1652)
        at javax.swing.UIManager.<clinit>(UIManager.java:313)

Comments
EVALUATION Sigh. Its not too surprising this happened. Headless mode was completely broken when the work involved in 6288260 was done. In fact a test for headless mode was included but wasn't enabled because of that. Headless was fixed in b47 but only *after* this work went back into b47. The CCE comes from code that is only called by a subclass of SunToolkit in the expectation that in Headless mode this can't be reached. initializeDesktopProperties() does nothing in HeadlessToolkit It was overlooked that java.awt.Toolkit.getDesktopProperty() has workaround code that explicitly checks for headless and redirects that case to the underlying toolkit. Need to fix the breakage and update the test - which should explicitly test Swing as well as the desktop property.
01-09-2005

EVALUATION Seems like a regression from "Fixed 6288260: RFE: Provide a means to get desktop font smoothing (text antialiasing) settings.", SunToolkit.java, 1.97.2.1, prr
01-09-2005