JDK-6607186 : ClassCastException casting to sun.awt.Win32GraphicsEnvironment
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 6
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2007-09-20
  • Updated: 2012-01-16
Description
FULL PRODUCT VERSION :
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b05)
Java HotSpot(TM) Client VM (build 1.6.0_02-b05, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.0.6000] (Vista)

EXTRA RELEVANT SYSTEM CONFIGURATION :
Dell XPS M1710 laptop

Eclipse Platform
Version: 3.3.0
Build id: I20070621-1340

  Tomcat Plugin com.sysdeo.eclipse.tomcat 3.2.1

Apache Tomcat 6.0.10



A DESCRIPTION OF THE PROBLEM :
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: sun.java2d.HeadlessGraphicsEnvironment cannot be cast to sun.awt.Win32GraphicsEnvironment
	at sun.awt.windows.WToolkit$4.run(WToolkit.java:755)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use the Eclipse IDE with the sysdeo tomcatplugin to start tomcat.
After tomcat startup, verify a webapp is working.
Close the lid of the laptop, causing the system to go into sleep, not hibernate.
Wait till all activity stops.
Open the lid and log in.
Eclipse now shows a breakpoint in EventDispatchTread.run()
After clicking run the following stacktrace is produced:

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: sun.java2d.HeadlessGraphicsEnvironment cannot be cast to sun.awt.Win32GraphicsEnvironment
	at sun.awt.windows.WToolkit$4.run(WToolkit.java:755)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

The running programs (tomcat, eclipse) do not seem to be bothered by this exception and happily continue.

The relevant code from the run method looks like this:
public void run() {
	try {
	    pumpEvents(new Conditional() {
		public boolean evaluate() {
		    return true;
		}
	    });
	} finally {
	    /*
	     * This synchronized block is to secure that the event dispatch
	     * thread won't die in the middle of posting a new event to the
	     * associated event queue. It is important because we notify
	     * that the event dispatch thread is busy after posting a new event
	     * to its queue, so the EventQueue.dispatchThread reference must
	     * be valid at that point.
	     */
	    synchronized (theQueue) {
                if (theQueue.getDispatchThread() == this) {
                    theQueue.detachDispatchThread();
                }
                /*
                 * Event dispatch thread dies in case of an uncaught exception.
                 * A new event dispatch thread for this queue will be started
                 * only if a new event is posted to it. In case if no more
                 * events are posted after this thread died all events that
                 * currently are in the queue will never be dispatched.
                 */
                /*
                 * Fix for 4648733. Check both the associated java event
                 * queue and the PostEventQueue.
                 */
                if (theQueue.peekEvent() != null ||
                    !SunToolkit.isPostEventQueueEmpty()) {
                    theQueue.initDispatchThread();
                }
		AWTAutoShutdown.getInstance().notifyThreadFree(this);
	    } <--location of breakpoint in eclipse
	}
    }


REPRODUCIBILITY :
This bug can be reproduced always.