FULL PRODUCT VERSION :
This issue is there starting from JDK 1.7
A DESCRIPTION OF THE PROBLEM :
EventQueue.pop() does not stop dispatch thread as specified in the API documentation. I have checked in the source code, and observed that below line of code is missing from JDK 1.7.
dispatchThread.stopDispatching();
the above line of code is present in JDK 1.6 and earlier versions.
REGRESSION. Last worked in version 6u45
ADDITIONAL REGRESSION INFORMATION:
JDK 6 and earlier versions
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run below code in JDK 7 and later versions
Run below code in JDK 6 and prior versions
SwingUtilities.isEventDispatchThread() - returns different values after push/pop
package com.dev.test;
import java.awt.AWTEvent;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.lang.reflect.InvocationTargetException;
import javax.swing.SwingUtilities;
public class EventQueueTest {
public static void main(String[] args) throws InterruptedException, InvocationTargetException {
setQueue();
System.out.println(Thread.currentThread());
System.out.println("aa"+SwingUtilities.isEventDispatchThread());
EventQueue.invokeLater(new Runnable() {
public void run() {
System.out.println("aa11"+SwingUtilities.isEventDispatchThread());
setQueue();
MyEventQueue eventQueue = (MyEventQueue)Toolkit.getDefaultToolkit().getSystemEventQueue();
System.out.println("Run");
System.out.println(Thread.currentThread());
System.out.println("aa1"+SwingUtilities.isEventDispatchThread());
eventQueue.pop();
System.out.println(Thread.currentThread());
System.out.println("aa3"+SwingUtilities.isEventDispatchThread());
}
});
System.out.println(Thread.currentThread());
System.out.println("aa2"+SwingUtilities.isEventDispatchThread());
}
private static EventQueue setQueue() {
EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();
eventQueue.push(new MyEventQueue());
return eventQueue;
}
private static class MyEventQueue extends EventQueue {
public void postEvent(AWTEvent theEvent) {
System.out.println("Event Posted");
super.postEvent(theEvent);
}
public void pop() {
super.pop();
}
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
SwingUtilities.isEventDispatchThread() - should return false after push/pop
ACTUAL -
SwingUtilities.isEventDispatchThread() - return true after push/pop
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No errors
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package com.dev.test;
import java.awt.AWTEvent;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.lang.reflect.InvocationTargetException;
import javax.swing.SwingUtilities;
public class EventQueueTest {
public static void main(String[] args) throws InterruptedException, InvocationTargetException {
setQueue();
System.out.println(Thread.currentThread());
System.out.println("aa"+SwingUtilities.isEventDispatchThread());
EventQueue.invokeLater(new Runnable() {
public void run() {
System.out.println("aa11"+SwingUtilities.isEventDispatchThread());
setQueue();
MyEventQueue eventQueue = (MyEventQueue)Toolkit.getDefaultToolkit().getSystemEventQueue();
System.out.println("Run");
System.out.println(Thread.currentThread());
System.out.println("aa1"+SwingUtilities.isEventDispatchThread());
eventQueue.pop();
System.out.println(Thread.currentThread());
System.out.println("aa3"+SwingUtilities.isEventDispatchThread());
}
});
System.out.println(Thread.currentThread());
System.out.println("aa2"+SwingUtilities.isEventDispatchThread());
}
private static EventQueue setQueue() {
EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();
eventQueue.push(new MyEventQueue());
return eventQueue;
}
private static class MyEventQueue extends EventQueue {
public void postEvent(AWTEvent theEvent) {
System.out.println("Event Posted");
super.postEvent(theEvent);
}
public void pop() {
super.pop();
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Could not find any workaround
SUPPORT :
YES