CDV ❯ toArray(Object[] a) in CHM keySet() breaks while concurrently modifying the map
-
Bug
-
Status: Closed
-
2 Major
-
Resolution: Fixed
-
Byte Code Transform
-
-
cdennis
-
Reporter: cdennis
-
May 26, 2009
-
0
-
Watchers: 1
-
August 20, 2009
-
May 26, 2009
Description
There is a bug in the ConcurrentHashMapKeySetWrapper toArray method whereby it does a size check on the map, and then uses the key set iterator to fill the array without worrying about the fact that the application might be modifying the map concurrently with the toArray call. This can cause the array being filled to then become not large enough to fit the entire key set.
I believe this is causing the error in http://forums.terracotta.org/forums/posts/list/2175.page
Workaround would be to oversize the array being passed (assuming you have access to the source code).
Comments
Tim Eck 2009-05-26
Chris Dennis 2009-05-26
Rely on the original implementation of toArray - there is no need to do anything more than a pass-through for this method.
Kalai Kannaiyan 2009-08-12
Verified the fix on trunk with svn rev12785
I should read the code before making this comment, but just oversizing “sounds” like it would still contain a race. It might be okay to fullLock() the thing while taking the toArray() like CHM.size() does