<AWT Dev> wrong logic to prevent recursion in SunToolkit.flushPendingEvents()
Peter Levart
peter.levart at gmail.com
Thu Jun 28 00:36:08 PDT 2012
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
More information about the awt-dev
mailing list