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.
|