--- old/src/share/classes/java/awt/EventQueue.java 2012-07-10 13:41:54.000000000 +0400 +++ new/src/share/classes/java/awt/EventQueue.java 2012-07-10 13:41:53.000000000 +0400 @@ -39,11 +39,12 @@ import sun.util.logging.PlatformLogger; import sun.awt.AppContext; +import sun.awt.AWTAccessor; import sun.awt.AWTAutoShutdown; +import sun.awt.AWTInterruptedException; import sun.awt.PeerEvent; import sun.awt.SunToolkit; import sun.awt.EventQueueItem; -import sun.awt.AWTAccessor; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; @@ -1038,15 +1039,17 @@ pushPopLock.lock(); try { if (edt == dispatchThread) { - /* - * Don't detach the thread if any events are pending. Not - * sure if it's a possible scenario, though. - * - * Fix for 4648733. Check both the associated java event - * queue and the PostEventQueue. - */ - if (!forceDetach && (peekEvent() != null) || !SunToolkit.isPostEventQueueEmpty()) { - return false; + if (peekEvent() != null || !SunToolkit.isPostEventQueueEmpty()) { + if (!forceDetach) { + /* + * Fix for 4648733. Check both the associated java event + * queue and the PostEventQueue. + */ + return false; + } else { + // 7162144 - derail pending events + removeAllEvents(); + } } dispatchThread = null; } @@ -1128,6 +1131,39 @@ } } + private void removeAllEvents() { + SunToolkit.flushPendingEvents(); + pushPopLock.lock(); + try { + for (int i = 0; i < NUM_PRIORITIES; i++) { + EventQueueItem entry = queues[i].head; + EventQueueItem prev = null; + while (entry != null) { + if (entry.event instanceof InvocationEvent) { + AWTAccessor.getInvocationEventAccessor(). + dispose((InvocationEvent)entry.event); + } + if (entry.event instanceof SequencedEvent) { + ((SequencedEvent)entry.event).dispose(); + } + if (entry.event instanceof SentEvent) { + ((SentEvent)entry.event).dispose(); + } + if (prev == null) { + queues[i].head = entry.next; + } else { + prev.next = entry.next; + } + uncacheEQItem(entry); + entry = entry.next; + } + queues[i].tail = prev; + } + } finally { + pushPopLock.unlock(); + } + } + static void setCurrentEventAndMostRecentTime(AWTEvent e) { Toolkit.getEventQueue().setCurrentEventAndMostRecentTimeImpl(e); } @@ -1235,7 +1271,11 @@ Throwable eventThrowable = event.getThrowable(); if (eventThrowable != null) { - throw new InvocationTargetException(eventThrowable); + if (eventThrowable instanceof AWTInterruptedException) { + throw new InterruptedException(eventThrowable.getMessage()); + } else { + throw new InvocationTargetException(eventThrowable); + } } }