-
Bug
-
Resolution: Fixed
-
P4
-
8u20
-
b36
-
x86
-
os_x
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8085422 | emb-9 | Maurizio Cimadamore | P4 | Resolved | Fixed | team |
FULL PRODUCT VERSION :
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Darwin dd 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
A DESCRIPTION OF THE PROBLEM :
Recently I filed an eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=442929. Srikanth Sankaran and Timo Kinnunen investigated that it is likely a javac bug.
In a nutshell, methods which create generic arrays internally and then let those arrays escape from the generic type's scope are unusable for their callers - but javac misses to type check these cases.
Please follow the above link to get additional examples and a detailed description of the bug.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Please compile and run the example source code provided here as follows:
$ javac MissingTypeCheck.java
$ java MissingTypeCheck
The program should terminate with return code 0 (no error).
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Javac is expected to generate byte code which performs an additional type check. When running the example source code provided here, an exception similar to this should be thrown:
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
at MissingTypeCheck.main(MissingTypeCheck.java:11)
ACTUAL -
No type check is performed / no exception is thrown.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
// credits for this test go to Timo Kinnunen
class MissingTypeCheck {
public static void main(String[] args) {
// -- does not throw compiled with javac (correct)
MissingTypeCheck.<String> newArray();
// -- does not throw compiled with javac (NOT CORRECT)
// -- JAVAC SHOULD PERFORM A TYPE CHECK HERE
assertNothing(MissingTypeCheck.<String> newArray());
// -- throws compiled with javac (correct)
// String[] hopeless = newArray();
}
static <T> void assertNothing(T actual) {
/* nada */
}
static <T> T[] newArray() {
@SuppressWarnings("unchecked")
T[] array = (T[]) new Object[0];
return array;
}
}
---------- END SOURCE ----------
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Darwin dd 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
A DESCRIPTION OF THE PROBLEM :
Recently I filed an eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=442929. Srikanth Sankaran and Timo Kinnunen investigated that it is likely a javac bug.
In a nutshell, methods which create generic arrays internally and then let those arrays escape from the generic type's scope are unusable for their callers - but javac misses to type check these cases.
Please follow the above link to get additional examples and a detailed description of the bug.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Please compile and run the example source code provided here as follows:
$ javac MissingTypeCheck.java
$ java MissingTypeCheck
The program should terminate with return code 0 (no error).
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Javac is expected to generate byte code which performs an additional type check. When running the example source code provided here, an exception similar to this should be thrown:
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
at MissingTypeCheck.main(MissingTypeCheck.java:11)
ACTUAL -
No type check is performed / no exception is thrown.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
// credits for this test go to Timo Kinnunen
class MissingTypeCheck {
public static void main(String[] args) {
// -- does not throw compiled with javac (correct)
MissingTypeCheck.<String> newArray();
// -- does not throw compiled with javac (NOT CORRECT)
// -- JAVAC SHOULD PERFORM A TYPE CHECK HERE
assertNothing(MissingTypeCheck.<String> newArray());
// -- throws compiled with javac (correct)
// String[] hopeless = newArray();
}
static <T> void assertNothing(T actual) {
/* nada */
}
static <T> T[] newArray() {
@SuppressWarnings("unchecked")
T[] array = (T[]) new Object[0];
return array;
}
}
---------- END SOURCE ----------
- backported by
-
JDK-8085422 Code generation problem with javac skipping a checkcast instruction
- Resolved