JDK-8144759 : EventQueue.pop() does not stop dispatching thread
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-11-09
  • Updated: 2016-03-19
  • Resolved: 2016-03-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 9
9Resolved
Related Reports
Relates :  
Description
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


Comments
Actually the documentation does not state that "SwingUtilities.isEventDispatchThread() - should return false after push/pop" see https://bugs.openjdk.java.net/browse/JDK-6424157
19-03-2016

Has a test case
04-12-2015