-
Bug
-
Resolution: Fixed
-
P4
-
8, 11, 17, 18, 19, 20
-
b21
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
This issue also occurs on JDK 8, 11, 17 and 19.
A DESCRIPTION OF THE PROBLEM :
The javadoc for java.util.List.set(E) indicates that the method will throw a ClassCastException if the class of the specified element prevents it from being added to this list, but Lists returned by Arrays.asList(E...) throw an ArrayStoreException when trying to set an element with a wrong type, which is undocumented.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the following code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Throws ClassCastException
ACTUAL -
Throws ArrayStoreException
---------- BEGIN SOURCE ----------
public class Main {
@SuppressWarnings({"rawtypes", "unchecked"})
public static void main(String[] args) {
List list = Arrays.asList(new String[1]);
list.set(0, 0);
}
}
---------- END SOURCE ----------
FREQUENCY : always
This issue also occurs on JDK 8, 11, 17 and 19.
A DESCRIPTION OF THE PROBLEM :
The javadoc for java.util.List.set(E) indicates that the method will throw a ClassCastException if the class of the specified element prevents it from being added to this list, but Lists returned by Arrays.asList(E...) throw an ArrayStoreException when trying to set an element with a wrong type, which is undocumented.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the following code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Throws ClassCastException
ACTUAL -
Throws ArrayStoreException
---------- BEGIN SOURCE ----------
public class Main {
@SuppressWarnings({"rawtypes", "unchecked"})
public static void main(String[] args) {
List list = Arrays.asList(new String[1]);
list.set(0, 0);
}
}
---------- END SOURCE ----------
FREQUENCY : always
- csr for
-
JDK-8307074 Arrays.asList() can return a List that throws undocumented ArrayStoreException
-
- Closed
-