Synchronize all appropriate methods in ConsistentHash.
Only add(T, int) was synchronized (and its javadoc claimed it was the only one modifying .items), but all the bulk add methods were going straight to addInternal() and then refreshTable() on their own. Then countAllPoints() was iterating over items.values() which has undefined behavior if the underlying Map changed. Technically I didn't need to synchronize the current implementations of remove(T) and add(T) since they delegated fully to add(T, int), but that's leaking implementation details and inviting trouble down the road when someone doesn't realize that. Likewise, addInternal() and refreshTable() need not be synchronized since they're only ever called from already synchronized methods, but I'm inclined to go for belt & suspenders in the wake of these other issues.
Loading
Please register or sign in to comment