While looking at the SunToolkit code I spoted another bug. The following code:
private static final Lock flushLock = new ReentrantLock();
private static boolean isFlushingPendingEvents = false;
/*
* Flush any pending events which haven't been posted to the AWT
* EventQueue yet.
*/
public static void flushPendingEvents() {
flushLock.lock();
try {
// Don't call flushPendingEvents() recursively
if (!isFlushingPendingEvents) {
isFlushingPendingEvents = true;
AppContext appContext = AppContext.getAppContext();
PostEventQueue postEventQueue =
(PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
if (postEventQueue != null) {
postEventQueue.flush();
}
}
} finally {
isFlushingPendingEvents = false;
flushLock.unlock();
}
}
... is clearly wrong. The isFlushingPendingEvents flag is reset in finally
block regardless of whether it was true or false at the entry to the try
block.
The 1st nested call to flushPendingEvents() prevents recursion but it also
resets the flag so that the second nested call is allowed...
Regards, Peter