United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6828273 javax/swing/system/6799345/TestShutdown.java test fails with RuntimeException.
JDK-6828273 : javax/swing/system/6799345/TestShutdown.java test fails with RuntimeException.

Details
Type:
Bug
Submit Date:
2009-04-09
Status:
Closed
Updated Date:
2011-03-07
Project Name:
JDK
Resolved Date:
2011-03-07
Component:
client-libs
OS:
solaris_10
Sub-Component:
java.awt
CPU:
sparc
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Relates:
Relates:
Relates:

Sub Tasks

Description
Bug Info
========
The test fails with RuntimeException on solaris 10 sparc and RHEL5.2 platforms.

javax/swing/system/6799345/TestShutdown.java

JDK Info:
=========
java version "1.7.0-internal"
Java(TM) SE Runtime Environment (build 1.7.0-internal-administrator_2009_04_01_1
5_11-b00)
Java HotSpot(TM) Client VM (build 15.0-b03, mixed mode)

Paltforms
==========
OS: Solaris sparc 10 
OS : RHEL 5.2


Exception Details
=================
AWT blocker activation interrupted:
java.lang.InterruptedException
	at java.lang.Object.wait(Native Method)
	at java.lang.Object.wait(Object.java:502)
	at sun.awt.AWTAutoShutdown.activateBlockerThread(AWTAutoShutdown.java:331)
	at sun.awt.AWTAutoShutdown.notifyThreadBusy(AWTAutoShutdown.java:168)
	at java.awt.EventQueue.initDispatchThread(EventQueue.java:847)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:170)
Test FAILED: an exception is caught in the target thread group on thread AWT-XAWT
java.lang.IllegalMonitorStateException
	at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:155)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1193)
	at java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:459)
	at sun.awt.SunToolkit.awtUnlock(SunToolkit.java:277)
	at sun.awt.X11.XToolkit.run(XToolkit.java:634)
	at sun.awt.X11.XToolkit.run(XToolkit.java:561)
	at java.lang.Thread.run(Thread.java:717)
java.lang.RuntimeException: Test FAILED: some exceptions occurred
	at TestShutdown.main(TestShutdown.java:69)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:623)
	at com.sun.javatest.regtest.MainWrapper$MainThread.run(MainWrapper.java:94)
	at java.lang.Thread.run(Thread.java:717)

                                    

Comments
EVALUATION

Assigned to the RE of the bug #6799345
                                     
2009-06-23
EVALUATION

At a first glance, this bug looks pretty strange. Indeed, in the fix for 6799345 I included the check to XToolkit.run():

            if (Thread.currentThread().isInterrupted()) {
                System.err.println("interrupted");
                // We expect interruption from the AppContext.dispose() method only.
                // If the thread is interrupted from another place, let's skip it
                // for compatibility reasons. Probably some time later we'll remove
                // the check for AppContext.isDisposed() and will unconditionally
                // break the loop here.
                if (AppContext.getAppContext().isDisposed()) {
                    break;
                }
            }

just to cover that particular case of AppContext disposal. Still, an exception is thrown from awtUnlock()... That's strange.

The next step is to insert some debug output to the code and try to find what's going. Surprisingly, the very first println discovered a problem. I logged the current thread's ThreadGroup and the current AppContext in two different places: at the beginning of XToolkit.run() and in the beginning of the test. The output was:

XToolkit AppContext = sun.awt.AppContext[threadGroup=system]
XToolkit ThreadGroup = TestShutdown$TestThreadGroup[name=TTG,maxpri=10]
Test AppContext = sun.awt.AppContext[threadGroup=TTG]
Test ThreadGroup = TestShutdown$TestThreadGroup[name=TTG,maxpri=10]

What looks really, really strange is that XToolkit's thread group is not "system", but "TTG" - thread group created in the test - while its AppContext is "system". However, after some investigation I've found the reason: toolkit is created in TestRunnable (which runs in TTG) before the call to SunToolkit.createAppContext() is completed. That's why toolkit "inherits" AppContext value from the parent thread group.

Given that, I see several possible solutions:

1. Lowest-risk fix: correct the test and call Toolkit.getDefaultToolkit() at the very beginning of the main() method.

2. Create the toolkit thread in a system thread group regardless of which thread XToolkit is initialized. In fact we already have the related code in XToolkit ctor: see 'mainTG' local variable which is never used. The fix may be to use mainTG as a thread group for the toolkit thread.
                                     
2009-06-26



Hardware and Software, Engineered to Work Together