mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
6260652: (coll) Arrays.asList(x).toArray().getClass() should be Object[].class
Return Arrays.copyOf(a, a.length, Object[].class) Reviewed-by: igerasim, psandoz
This commit is contained in:
parent
99f867bded
commit
57996d703c
6 changed files with 10 additions and 12 deletions
|
@ -178,7 +178,8 @@ public class ArrayList<E> extends AbstractList<E>
|
|||
public ArrayList(Collection<? extends E> c) {
|
||||
elementData = c.toArray();
|
||||
if ((size = elementData.length) != 0) {
|
||||
// c.toArray might (incorrectly) not return Object[] (see 6260652)
|
||||
// defend against c.toArray (incorrectly) not returning Object[]
|
||||
// (see e.g. https://bugs.openjdk.java.net/browse/JDK-6260652)
|
||||
if (elementData.getClass() != Object[].class)
|
||||
elementData = Arrays.copyOf(elementData, size, Object[].class);
|
||||
} else {
|
||||
|
|
|
@ -3820,7 +3820,7 @@ public class Arrays {
|
|||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
return a.clone();
|
||||
return Arrays.copyOf(a, a.length, Object[].class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -174,7 +174,8 @@ public class Vector<E>
|
|||
public Vector(Collection<? extends E> c) {
|
||||
elementData = c.toArray();
|
||||
elementCount = elementData.length;
|
||||
// c.toArray might (incorrectly) not return Object[] (see 6260652)
|
||||
// defend against c.toArray (incorrectly) not returning Object[]
|
||||
// (see e.g. https://bugs.openjdk.java.net/browse/JDK-6260652)
|
||||
if (elementData.getClass() != Object[].class)
|
||||
elementData = Arrays.copyOf(elementData, elementCount, Object[].class);
|
||||
}
|
||||
|
|
|
@ -134,7 +134,8 @@ public class CopyOnWriteArrayList<E>
|
|||
elements = ((CopyOnWriteArrayList<?>)c).getArray();
|
||||
else {
|
||||
elements = c.toArray();
|
||||
// c.toArray might (incorrectly) not return Object[] (see 6260652)
|
||||
// defend against c.toArray (incorrectly) not returning Object[]
|
||||
// (see e.g. https://bugs.openjdk.java.net/browse/JDK-6260652)
|
||||
if (elements.getClass() != Object[].class)
|
||||
elements = Arrays.copyOf(elements, elements.length, Object[].class);
|
||||
}
|
||||
|
|
|
@ -142,7 +142,8 @@ public class IdentityArrayList<E> extends AbstractList<E>
|
|||
public IdentityArrayList(Collection<? extends E> c) {
|
||||
elementData = c.toArray();
|
||||
size = elementData.length;
|
||||
// c.toArray might (incorrectly) not return Object[] (see 6260652)
|
||||
// defend against c.toArray (incorrectly) not returning Object[]
|
||||
// (see e.g. https://bugs.openjdk.java.net/browse/JDK-6260652)
|
||||
if (elementData.getClass() != Object[].class)
|
||||
elementData = Arrays.copyOf(elementData, size, Object[].class);
|
||||
}
|
||||
|
|
|
@ -356,13 +356,7 @@ public class MOAT {
|
|||
}
|
||||
|
||||
check(c.toArray().length == c.size());
|
||||
check(c.toArray().getClass() == Object[].class
|
||||
||
|
||||
// !!!!
|
||||
// 6260652: (coll) Arrays.asList(x).toArray().getClass()
|
||||
// should be Object[].class
|
||||
(c.getClass().getName().equals("java.util.Arrays$ArrayList"))
|
||||
);
|
||||
check(c.toArray().getClass() == Object[].class);
|
||||
for (int size : new int[]{0,1,c.size(), c.size()+1}) {
|
||||
Integer[] a = c.toArray(new Integer[size]);
|
||||
check((size > c.size()) || a.length == c.size());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue