-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
8u212
-
x86_64
-
linux_ubuntu
A DESCRIPTION OF THE PROBLEM :
I'm using the ArrayList toArray method with parameter. The array passed to method toArray is big enough to "force" the toArray method to use the parameters array for the return.
The problem is that the value at the index = list.size overiting the arrays value with null (see code bellow value "magic").
import java.util.*;
public class ArrayesTest {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("l1");
list.add("l2");
String [] a = new String[5];
a[2] = "magic";
a[3] = "a1";
a[4] = "a2";
String[] stringArray = list.toArray(a);
System.out.println(stringArray.length);
for(String s : a)
System.out.println(s);
}
}
FREQUENCY : always
I'm using the ArrayList toArray method with parameter. The array passed to method toArray is big enough to "force" the toArray method to use the parameters array for the return.
The problem is that the value at the index = list.size overiting the arrays value with null (see code bellow value "magic").
import java.util.*;
public class ArrayesTest {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("l1");
list.add("l2");
String [] a = new String[5];
a[2] = "magic";
a[3] = "a1";
a[4] = "a2";
String[] stringArray = list.toArray(a);
System.out.println(stringArray.length);
for(String s : a)
System.out.println(s);
}
}
FREQUENCY : always