JDK-6377302 : AbstractCollection.toArray is not safe for concurrent collections
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-01-26
  • Updated: 2017-05-16
  • Resolved: 2006-06-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b87Fixed
Related Reports
Relates :  
Relates :  
Description
AbstractCollection.toArray assumes that size() is constant during 
method execution.  That makes the implementation unsafe for concurrent collections.
All concurrent collections provided by the JDK must override toArray, and
any third-party collections must do so as well, but are likely to not notice,
causing rare unpredictable runtime failures due to the inherent race condition.

Comments
EVALUATION I just noticed that ConcurrentSkipListSet.toArray inherits the non-thread-safe version, so this bug is more serious and must be resolved in mustang. Test case is already written; just uncomment call to testSets() in BiggernYours.java.
11-05-2006

EVALUATION The toArray methods must be written (and spec'ed) to use size() only as a hint.
26-01-2006