-
Bug
-
Resolution: Fixed
-
P2
-
5.0
-
b49
-
x86
-
windows_2000
###@###.### 2004-03-16
J2SE Version (please include all output from java -version flag):
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b40)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b40, mixed mode)
Does this problem occur on J2SE 1.3.x or 1.4.x? Yes / No (pick one)
N/A
Operating System Configuration Information (be specific):
Windows 2000 Professional SP2
Bug Description:
Casting from an array of a wrapper type such as Integer to an array of the
corresponding primitive type is allowed by javac when using -source 1.5
despite the fact that it will cause a ClassCastException at runtime.
Casting in the opposite direction (eg. from float[] to Float[]) is not
permitted by the compiler.
Test Program: ArrayCast.java
// Start of ArrayCast.java
public class ArrayCast {
public static void main(String[] args) {
Integer[] integers = { };
int[] ints = (int[]) integers;
}
}
// End of ArrayCast.java
Steps to Reproduce (be specific):
1) Save the Test Program above as ArrayCast.java
2) javac -source 1.4 ArrayCast.java
3) Output from javac:
ArrayCast.java:4: inconvertible types
found : java.lang.Integer[]
required: int[]
int[] ints = (int[]) integers;
^
1 error
4) javac -source 1.5 ArrayCast.java
5) java ArrayCast
6) Output from java:
Exception in thread "main" java.lang.ClassCastException:
[Ljava.lang.Integer;
at ArrayCast.main(ArrayCast.java:4)