JDK-4932181 : EventQueue uses wait() outside of while loop
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0,5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2003-10-03
  • Updated: 2004-08-13
  • Resolved: 2004-08-13
Related Reports
Duplicate :  
Relates :  
Description
The Object.wait() method should ALWAYS be called from within a loop (checking a conditional variable) to protect from "spurious wakeup." This has always been the case, and 4308396 (committed to tiger) plans to make this very clear in the Object.wait() documentation.

While looking at the source for java.awt.EventQueue I discovered at least one usage of wait() outside of any loop. This usage occurs in the method invokeAndWait(). That call to wait() should be wrapped in a loop that checks a variable, rather than assuming that it IS time to wake up.

Also, there are a couple of other wait() calls in EventQueue that should be double checked to ensure they follow the rules.

Comments
EVALUATION Name: osR10079 Date: 10/06/2003 I've checked that htere is the only place in EventQueue where we call wait() not within a loop is EventQueue.invokeAndWait(). But in this method we every time create new object which we will use for waitong, then we create InvocationEvent with this object as "notifier" parameter of its ctor. After that InvocationEvent use it in one place to notify that method Runnable.run() finished. And this behavior of InvocationEvent is documented, so using notifier for another synchronization will break contract of InvocationEvent class. Thus in this particular case there is no problem with such usage of Object.wait() method. ======================================================================
14-08-2004