Details
-
Bug
-
Status: Resolved
-
Resolution: Won't Do
-
None
-
None
-
None
-
None
-
Operating System: All
Platform: All
-
1570
Description
There's a couple issues in InMemoryDataTree wrt to synchronization:
1) There's redundant synchronization in the setSchemaContext, validate, prepare and commit methods, ie the methods are both synchronized and they use the read/write lock. The synchronized keyword should be removed (it's not good practice anyway to synchronize methods). I suspect the read/write lock was added afterwards and the person forgot to remove synchronized.
2) The validate method accesses the 'rootNode' member completely unsynchronized. This is unsafe - all accesses to 'rootNode' must be synchronized wrt to one another. Since validate doesn't modify the 'rootNode' it can acquire the read lock. It passes 'rootNode' to another class and I don't think we need to hold the lock across that call so we should be able to do:
TreeNode localRootNode;
rwLock.readLock().lock();
try
finally
{ rwLock.readLock().unlock(); }m.getStrategy().checkApplicable(..., Optional.<TreeNode>of(localRootNode));