A DESCRIPTION OF THE PROBLEM :
It appears `javac` emits a duplicate `checkcast` for the first bound of an intersection type as part of a cast expression.
Possibly related toJDK-8011392
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile the class IntersectionTypeTest provided below
2. Decompile the class file with `javap -v`
3. Look at the byte code for method `test2`
ACTUAL -
1: checkcast #9 // class IntersectionTypeTest$C1
4: checkcast #7 // class IntersectionTypeTest$I1
7: checkcast #9 // class IntersectionTypeTest$C1
---------- BEGIN SOURCE ----------
class IntersectionTypeTest {
interface I1 { }
static class C1 { }
static Object test(Object o) {
// As expected: Single checkcast I1
return (I1) o;
}
static Object test2(Object o) {
// Unexpected: Duplicate checkcast C1
return (C1 & I1) o;
}
}
---------- END SOURCE ----------
It appears `javac` emits a duplicate `checkcast` for the first bound of an intersection type as part of a cast expression.
Possibly related to
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile the class IntersectionTypeTest provided below
2. Decompile the class file with `javap -v`
3. Look at the byte code for method `test2`
ACTUAL -
1: checkcast #9 // class IntersectionTypeTest$C1
4: checkcast #7 // class IntersectionTypeTest$I1
7: checkcast #9 // class IntersectionTypeTest$C1
---------- BEGIN SOURCE ----------
class IntersectionTypeTest {
interface I1 { }
static class C1 { }
static Object test(Object o) {
// As expected: Single checkcast I1
return (I1) o;
}
static Object test2(Object o) {
// Unexpected: Duplicate checkcast C1
return (C1 & I1) o;
}
}
---------- END SOURCE ----------
- relates to
-
JDK-8011392 Missing checkcast when casting to intersection type
-
- Closed
-
-
JDK-8268885 duplicate checkcast when destination type is not first type of intersection type
-
- Resolved
-