mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8231800: Better listing of arrays
Reviewed-by: alanb, rhalade, ahgross, igerasim
This commit is contained in:
parent
0ffa6b75fd
commit
343ecd806b
5 changed files with 25 additions and 22 deletions
|
@ -178,15 +178,16 @@ public class ArrayList<E> extends AbstractList<E>
|
|||
* @throws NullPointerException if the specified collection is null
|
||||
*/
|
||||
public ArrayList(Collection<? extends E> c) {
|
||||
elementData = c.toArray();
|
||||
if ((size = elementData.length) != 0) {
|
||||
// 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);
|
||||
Object[] a = c.toArray();
|
||||
if ((size = a.length) != 0) {
|
||||
if (c.getClass() == ArrayList.class) {
|
||||
elementData = a;
|
||||
} else {
|
||||
elementData = Arrays.copyOf(a, size, Object[].class);
|
||||
}
|
||||
} else {
|
||||
// replace with empty array.
|
||||
this.elementData = EMPTY_ELEMENTDATA;
|
||||
elementData = EMPTY_ELEMENTDATA;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue