Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6887249
Votes 0
Synopsis Get rid of double-check for isValid() idiom in validate() methods
Category java:classes_awt
Reported Against
Release Fixed 7(b77)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs
Submit Date 01-OCT-2009
Description
The Container.validate() method uses the following idiom to boost the performance:

if (!isValid()) {
   synchronized (getTreeLock()) {
      if (!isValid()) {
         // here go all the real actions
      }
   }
}

This was done to avoid grabbing the lock when it doesn't seem to be needed. However, the isValid() method actually retrieves the value of the 'valid' private memeber which must only be updated while holding the lock. That means that reading the value w/o the lock may theoretically produce an incorrect result.

Therefore, it is suggested to remove the outer if () statement and only check for validity under the lock.
Posted Date : 2009-10-01 10:13:20.0
Work Around
N/A
Evaluation
Need to check for isValid() under the TreeLock only.
Posted Date : 2009-10-01 11:25:15.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang