Request for review : 7121314 : Behavior mismatch between AbstractCollection.toArray(T[] ) and its spec (original) (raw)
David Holmes david.holmes at oracle.com
Sat Mar 10 12:52:21 UTC 2012
- Previous message: Request for review : 7121314 : Behavior mismatch between AbstractCollection.toArray(T[] ) and its spec
- Next message: Request for review : 7121314 : Behavior mismatch between AbstractCollection.toArray(T[] ) and its spec
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 10/03/2012 12:02 PM, Ulf Zibis wrote:
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[] toArray(T[] a) ? This would prevent from the cast r[i] = (T)it.next();
It's too late to change the method signature now.
Wouldn't following statement potentially throw a ClassCastException ? r[i] = (T)it.next();
Apparently not. I passed in a String[] when it should be Object[] and got ArrayStoreException. Checking the bytecode I don't see a checkcast.
David
... 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.
-Ulf
- Previous message: Request for review : 7121314 : Behavior mismatch between AbstractCollection.toArray(T[] ) and its spec
- Next message: Request for review : 7121314 : Behavior mismatch between AbstractCollection.toArray(T[] ) and its spec
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]