Details
-
Improvement
-
Status: Patch Available
-
Minor
-
Resolution: Unresolved
-
3.2.0
-
None
-
None
-
Patch
Description
Internal data structure needs to be protected (synchronized) but is scoped as protected so any sub-class could modify without a lock. Synchronize the collection itself for protection. It also returns the internal data structure in getLocations so the structure could be modified outside of the lock. Create a copy instead.
/** The locations of the replicas of the block. */ protected final List<L> locations = new ArrayList<L>(3); public Locations(Block block) { this.block = block; } /** clean block locations */ public synchronized void clearLocations() { locations.clear(); } ... /** @return its locations */ public synchronized List<L> getLocations() { return locations; }
Also, remove a bunch of superfluous and complicated code.