-
Bug
-
Resolution: Fixed
-
P3
-
14, 15, 16, 17, 18
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8274905 | 17.0.2 | Ekaterina Vergizova | P3 | Resolved | Fixed | b03 |
A DESCRIPTION OF THE PROBLEM :
Relates toJDK-8263642, possibly introduced by JDK-8209022
When an intersection type cast, e.g. `I1 & I2`, is used and the result of it is then used in a way where the expected type is one of the intersection type supertypes other then the first, e.g. `I2`, a duplicate `checkcast` is emitted for this type.
However, maybe this is a rare corner case which never actually occurs in reality because such Java source code makes no sense. And care must be taken to not reintroduceJDK-8209022.
REGRESSION : Last worked in version 11.0.11
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a source file `IntersectionTypeTest.java` with the code provided below
2. Compile it
3. Inspect the bytecode, e.g. using `javap -v`
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No duplicate `checkcast`
ACTUAL -
There are duplicate checkcasts e.g. here for `I2`:
void testSecond();
descriptor: ()V
flags: (0x0000)
Code:
stack=2, locals=2, args_size=1
0: new #7 // class IntersectionTypeTest$C
3: dup
4: invokespecial #9 // Method IntersectionTypeTest$C."<init>":()V
7: checkcast #10 // class IntersectionTypeTest$I2
10: checkcast #12 // class IntersectionTypeTest$I3
13: checkcast #14 // class IntersectionTypeTest$I1
16: checkcast #10 // class IntersectionTypeTest$I2
---------- BEGIN SOURCE ----------
class IntersectionTypeTest {
interface I1 { }
interface I2 { }
interface I3 { }
static class C { }
void testFirst() {
// No duplicate checkcast; first intersection type supertype is same as variable type
I1 i = (I1 & I2 & I3) new C();
}
void testSecond() {
// Duplicate checkcast for `I2`
I2 i = (I1 & I2 & I3) new C();
}
I3 testThirdReturn() {
// Also affects for example `return` statement; duplicate `checkcast` for `I3`
return (I1 & I2 & I3) new C();
}
}
---------- END SOURCE ----------
Relates to
When an intersection type cast, e.g. `I1 & I2`, is used and the result of it is then used in a way where the expected type is one of the intersection type supertypes other then the first, e.g. `I2`, a duplicate `checkcast` is emitted for this type.
However, maybe this is a rare corner case which never actually occurs in reality because such Java source code makes no sense. And care must be taken to not reintroduce
REGRESSION : Last worked in version 11.0.11
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a source file `IntersectionTypeTest.java` with the code provided below
2. Compile it
3. Inspect the bytecode, e.g. using `javap -v`
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No duplicate `checkcast`
ACTUAL -
There are duplicate checkcasts e.g. here for `I2`:
void testSecond();
descriptor: ()V
flags: (0x0000)
Code:
stack=2, locals=2, args_size=1
0: new #7 // class IntersectionTypeTest$C
3: dup
4: invokespecial #9 // Method IntersectionTypeTest$C."<init>":()V
7: checkcast #10 // class IntersectionTypeTest$I2
10: checkcast #12 // class IntersectionTypeTest$I3
13: checkcast #14 // class IntersectionTypeTest$I1
16: checkcast #10 // class IntersectionTypeTest$I2
---------- BEGIN SOURCE ----------
class IntersectionTypeTest {
interface I1 { }
interface I2 { }
interface I3 { }
static class C { }
void testFirst() {
// No duplicate checkcast; first intersection type supertype is same as variable type
I1 i = (I1 & I2 & I3) new C();
}
void testSecond() {
// Duplicate checkcast for `I2`
I2 i = (I1 & I2 & I3) new C();
}
I3 testThirdReturn() {
// Also affects for example `return` statement; duplicate `checkcast` for `I3`
return (I1 & I2 & I3) new C();
}
}
---------- END SOURCE ----------
- backported by
-
JDK-8274905 duplicate checkcast when destination type is not first type of intersection type
-
- Resolved
-
- relates to
-
JDK-8209022 Missing checkcast when casting to type parameter bounded by intersection type
-
- Closed
-
-
JDK-8263642 javac emits duplicate checkcast for first bound of intersection type in cast
-
- Closed
-
- links to
-
Commit openjdk/jdk17u/d13334d5
-
Commit openjdk/jdk/dd1209e4
-
Review openjdk/jdk17u/158
-
Review openjdk/jdk/5235
(2 links to)