-
Bug
-
Resolution: Fixed
-
P4
-
11
-
b13
-
Verified
In the following example the method 'f' completes without exceptions, and the method 'f' (which differs only in the order of the components of the bounds of its type parameter) fails with a CCE.
This seems similar toJDK-8011392. Should javac be emitting additional checkcasts for the components of the type parameters' bounds, or only for the erased type?
```
import java.util.*;
class T {
public static void main(String[] args) {
f();
g(); // CCE
}
static <T extends List<?> & Runnable> void f() {
Runnable r = (T) new ArrayList<>();
}
static <T extends Runnable & List<?>> void g() {
Runnable r = (T) new ArrayList<>();
}
}
```
$ javap T
...
static <T extends java.util.List<?> & java.lang.Runnable> void f();
descriptor: ()V
flags: (0x0008) ACC_STATIC
Code:
stack=2, locals=1, args_size=0
0: new #4 // class java/util/ArrayList
3: dup
4: invokespecial #5 // Method java/util/ArrayList."<init>":()V
7: astore_0
8: return
...
static <T extends java.lang.Runnable & java.util.List<?>> void g();
descriptor: ()V
flags: (0x0008) ACC_STATIC
Code:
stack=2, locals=1, args_size=0
0: new #4 // class java/util/ArrayList
3: dup
4: invokespecial #5 // Method java/util/ArrayList."<init>":()V
7: checkcast #6 // class java/lang/Runnable
10: astore_0
11: return
$ java T
Exception in thread "main" java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class java.lang.Runnable (java.util.ArrayList and java.lang.Runnable are in module java.base of loader 'bootstrap')
at T.g(T.java:14)
at T.main(T.java:6)
This seems similar to
```
import java.util.*;
class T {
public static void main(String[] args) {
f();
g(); // CCE
}
static <T extends List<?> & Runnable> void f() {
Runnable r = (T) new ArrayList<>();
}
static <T extends Runnable & List<?>> void g() {
Runnable r = (T) new ArrayList<>();
}
}
```
$ javap T
...
static <T extends java.util.List<?> & java.lang.Runnable> void f();
descriptor: ()V
flags: (0x0008) ACC_STATIC
Code:
stack=2, locals=1, args_size=0
0: new #4 // class java/util/ArrayList
3: dup
4: invokespecial #5 // Method java/util/ArrayList."<init>":()V
7: astore_0
8: return
...
static <T extends java.lang.Runnable & java.util.List<?>> void g();
descriptor: ()V
flags: (0x0008) ACC_STATIC
Code:
stack=2, locals=1, args_size=0
0: new #4 // class java/util/ArrayList
3: dup
4: invokespecial #5 // Method java/util/ArrayList."<init>":()V
7: checkcast #6 // class java/lang/Runnable
10: astore_0
11: return
$ java T
Exception in thread "main" java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class java.lang.Runnable (java.util.ArrayList and java.lang.Runnable are in module java.base of loader 'bootstrap')
at T.g(T.java:14)
at T.main(T.java:6)
- relates to
-
JDK-8268885 duplicate checkcast when destination type is not first type of intersection type
-
- Resolved
-
-
JDK-8011392 Missing checkcast when casting to intersection type
-
- Closed
-