Request for review : 7121314 : Behavior mismatch between AbstractCollection.toArray(T[] ) and its spec

Ulf Zibis Ulf.Zibis at
Sat Mar 10 02:02:44 UTC 2012

Am 09.03.2012 09:16, schrieb Sean Chou:
> Hi all,
>     AbstractCollection.toArray(T[] ) might return a new array even if the given array has enough 
> room for the returned elements when it is concurrently modified. This behavior violates the spec 
> documented in java.util.Collection .
>     This patch checks the size of returned array and copies the elements to return to the given 
> array if it is large enough.

More Questions:

Why don't we have
     public <T super E> T[] toArray(T[] a)  ?
This would prevent from the cast
         r[i] = (T);

Wouldn't following statement potentially throw a ClassCastException ?
         r[i] = (T);
... but the doc says, it should throw an ArrayStoreException, if the runtime type of the specified 
array is not a supertype of the runtime type of every element in this collection.


More information about the core-libs-dev mailing list