JDK-8152974 : AWT hang occurrs when sequenced events arrive out of sequence
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7,8u66,9,10,11
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2016-03-23
  • Updated: 2019-02-01
  • Resolved: 2018-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 11 JDK 8
11 b07Fixed 8u172Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) Client VM (build 25.66-b17, mixed mode)

Also seen with 8u51x86

ADDITIONAL OS VERSION INFORMATION :
Windows 7 Enterprise 64-bit (6.1, Build 7601) Service Pack 1 (7601.win7sp1_gdr.151230-0600)

EXTRA RELEVANT SYSTEM CONFIGURATION :
User systems I've seen this on tend to have a fair bit extra software (antivirus, skype, VNC server, etc, etc)

A DESCRIPTION OF THE PROBLEM :
As best as we can determine, system generated SequencedEvent(s) for window focus events (Focus Gained/Focus lost) are arriving into the event queue out of sequence.
I have a SSCE that demonstrates that out of sequence SequencedEvents generate a hang.
I'm not sure why the window events are arriving in the event queue out of sequence, timestamps between the first and second event have been seen to place the second event as having been created more than 20 seconds _before_ the first sequenced event, and also fewer than 200ms before.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create two sequenced events.  Submit them to the event queue in reverse order.

We're seeing this happen with system generated Window Focus events (Focus Gained/Focus Lost) on 8u51 and 8u66.  We're testing 8u74 (no results yet).  

The hang occurs every time the events arrive out of order, but they only arrive out of order infrequently.  Often enough to be a significant problem to users.  Rare enough to make troubleshooting difficult.  Thus far, the faulty events have all been observed to be window focus events.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Sequenced Event lives up to its stated design: 

A mechanism for ensuring that a series of AWTEvents are executed in a
 precise order, even across multiple AppContexts. The nested events will be
dispatched in the order in which their wrapping SequencedEvents were
constructed.

The second event to be submitted is processed first
ACTUAL -
The AWT Event Queue continues to queue events, but stops all event processing.  The application is effectively hung.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Stack of the event thread - it always contains a SequencedEvent in the stack.
Thread [AWT-EventQueue-0] (Suspended)	
	Unsafe.park(boolean, long) line: not available [native method]	
	LockSupport.park(Object) line: 175	
	AbstractQueuedSynchronizer$ConditionObject.await() line: 2039	
	EventQueue.getNextEvent(int) line: 608	
	EventDispatchThread.pumpOneEventForFilters(int) line: 170	
	EventDispatchThread.pumpEventsForFilter(int, Conditional, EventFilter) line: 116	
	EventDispatchThread.pumpEventsForHierarchy(int, Conditional, Component) line: 105	
	EventDispatchThread.pumpEvents(int, Conditional) line: 101	
	SequencedEvent.dispatch() line: 107	
	EventQueue.dispatchEventImpl(AWTEvent, Object) line: 756	
	EventQueue.access$500(EventQueue, AWTEvent, Object) line: 97	
	EventQueue$3.run() line: 709	
	EventQueue$3.run() line: 703	
	AccessController.doPrivileged(PrivilegedAction<T>, AccessControlContext) line: not available [native method]	
	ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(PrivilegedAction<T>, AccessControlContext, AccessControlContext) line: 76	
	ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(PrivilegedAction<T>, AccessControlContext) line: 86	
	EventQueue$4.run() line: 731	
	EventQueue$4.run() line: 729	
	AccessController.doPrivileged(PrivilegedAction<T>, AccessControlContext) line: not available [native method]	
	ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(PrivilegedAction<T>, AccessControlContext, AccessControlContext) line: 76	
	EventQueue.dispatchEvent(AWTEvent) line: 728	
	EventDispatchThread.pumpOneEventForFilters(int) line: 201	
	EventDispatchThread.pumpEventsForFilter(int, Conditional, EventFilter) line: 116	
	EventDispatchThread.pumpEventsForHierarchy(int, Conditional, Component) line: 105	
	EventDispatchThread.pumpEvents(int, Conditional) line: 101	
	EventDispatchThread.pumpEvents(Conditional) line: 93	
	EventDispatchThread.run() line: 82	


REPRODUCIBILITY :
This bug can be reproduced often.

---------- BEGIN SOURCE ----------
package test.unsequenced;

import java.awt.AWTEvent;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.Constructor;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;

public class DummyWindow extends JFrame implements ActionListener
{

    private static final long serialVersionUID = 1L;
    private JButton spamMeButton;

    public static void main(String[] args)
    {
        new DummyWindow().show();
    }
    
    public DummyWindow()
    {
        super("Test Window");
        
        setLayout(new FlowLayout());
        JTextArea textBlock = new JTextArea("Lorem ipsum dolor sit amet...");
        add(textBlock);

        spamMeButton = new JButton("Press me!");
        spamMeButton.addActionListener(this);
        add(spamMeButton);
        
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        pack();
    }

    @Override
    public void actionPerformed(ActionEvent e)
    {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        if(e.getSource() == spamMeButton)
        {
            AWTEvent eventOne = getSequencedEvent();
            AWTEvent eventTwo = getSequencedEvent();

            Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(eventTwo);
            Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(eventOne);
        }
        
    }
    
    private AWTEvent getSequencedEvent()
    {
        AWTEvent wrapMe = new AWTEvent(this, AWTEvent.RESERVED_ID_MAX+1) {};
        try
        {
            @SuppressWarnings("unchecked")
            Class<? extends AWTEvent> seqClass = (Class<? extends AWTEvent>) Class.forName("java.awt.SequencedEvent");
            Constructor<? extends AWTEvent> seqConst = seqClass.getConstructor(AWTEvent.class);
            seqConst.setAccessible(true);
            AWTEvent instance = seqConst.newInstance(wrapMe);
            return instance;
        } catch (Throwable err)
        {
            throw new Error("Unable to instantiate SequencedEvent",err);
        }
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None yet (still trying).


Comments
Webrev for review (8u-backport) - http://cr.openjdk.java.net/~dkumar/8152974/8u-dev_Backport/webrev.00/ Patch pushed for JDK 11 doesn���t apply cleanly to JDK 8, mainly because of the line differences and the key ���headful��� has been removed from the test file. Related Jtreg tests have been run against the proposed patch and results are fine.
05-04-2018

Krishna, please upload here in Comments the summary of proposed fix, review links and webrev
16-03-2018

Windows issue
30-01-2018

Yes. It affects 9. Also 7. Updated accordingly. Tested on Windows7 - 64 bit. Fix not known yet.
01-04-2016

does it affect 9?
29-03-2016