c.toArray might (incorrectly) not return Object[] (see 6260652)

David Holmes - Sun Microsystems David.Holmes at Sun.COM
Fri May 22 11:45:23 UTC 2009


Doug Lea said the following on 05/22/09 21:31:
> David Holmes - Sun Microsystems wrote:
>> Thanks for the info, one query though ...
>>
>> Ummm why didn't it just use:
>>
>>     elementData = c.toArray(new Object[c.size()]);
>>
> 
> Because "c" might be a concurrent collection, so you
> don't want to independently call c.size(). Notice
> that AbstractCollection correctly implements
> toArray() even for such collections but cannot do so
> for toArray(T[] a) because it must interpret
> a.length as the required size.

Has that code been updated recently because it sure looks like it tries 
to acommodate this and always return an array of exactly size() length 
(at the time toArray is called). ??

David



More information about the core-libs-dev mailing list