-
Bug
-
Resolution: Fixed
-
P4
-
21, 22
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8323207 | 21.0.3-oracle | Angelos Bimpoudis | P4 | Resolved | Fixed | b02 |
JDK-8322396 | 21.0.3 | Aleksey Shipilev | P4 | Resolved | Fixed | b01 |
Code:
class Test {
public static void main(String[] args) {
test(1);
test("hello");
}
record R1() {}
record R2() {}
static void test(Object o) {
switch (o) {
case R1() when o instanceof String s:
case R2() when o instanceof Integer i:
System.out.println("hello: " + i);
break;
default:
break;
}
}
}
Expected: should not be compilable: pattern variables declared in guard should not be visible in the switch label body.
Actual: Compilable (even without preview) and produces VerifyError at runtime:
Exception in thread "main" java.lang.VerifyError: Bad local variable type
Exception Details:
Location:
Test.test(Ljava/lang/Object;)V @73: aload_2
Reason:
Type integer (current frame, locals[2]) is not assignable to reference type
Current Frame:
bci: @73
flags: { }
locals: { 'java/lang/Object', 'java/lang/Object', integer }
stack: { 'java/io/PrintStream' }
Bytecode:
0000000: 2a59 b800 1557 4c03 3d2b 1cba 001b 0000
0000010: ab00 0000 0000 0045 0000 0002 0000 0000
0000020: 0000 001c 0000 0001 0000 0036 2bc0 001f
0000030: 4e2a c100 2199 000c 2ac0 0021 3a04 a700
0000040: 0804 3da7 ffc6 b200 232c ba00 2900 00b6
0000050: 002d a700 06a7 0003 b1
Stackmap Table:
append_frame(@9,Object[#2],Integer)
same_frame(@44)
append_frame(@65,Object[#31])
chop_frame(@70,1)
same_frame(@85)
chop_frame(@88,2)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:537)
at java.base/java.lang.Class.forName(Class.java:516)
at jdk.compiler/com.sun.tools.javac.launcher.Main.execute(Main.java:432)
at jdk.compiler/com.sun.tools.javac.launcher.Main.run(Main.java:208)
at jdk.compiler/com.sun.tools.javac.launcher.Main.main(Main.java:135)
class Test {
public static void main(String[] args) {
test(1);
test("hello");
}
record R1() {}
record R2() {}
static void test(Object o) {
switch (o) {
case R1() when o instanceof String s:
case R2() when o instanceof Integer i:
System.out.println("hello: " + i);
break;
default:
break;
}
}
}
Expected: should not be compilable: pattern variables declared in guard should not be visible in the switch label body.
Actual: Compilable (even without preview) and produces VerifyError at runtime:
Exception in thread "main" java.lang.VerifyError: Bad local variable type
Exception Details:
Location:
Test.test(Ljava/lang/Object;)V @73: aload_2
Reason:
Type integer (current frame, locals[2]) is not assignable to reference type
Current Frame:
bci: @73
flags: { }
locals: { 'java/lang/Object', 'java/lang/Object', integer }
stack: { 'java/io/PrintStream' }
Bytecode:
0000000: 2a59 b800 1557 4c03 3d2b 1cba 001b 0000
0000010: ab00 0000 0000 0045 0000 0002 0000 0000
0000020: 0000 001c 0000 0001 0000 0036 2bc0 001f
0000030: 4e2a c100 2199 000c 2ac0 0021 3a04 a700
0000040: 0804 3da7 ffc6 b200 232c ba00 2900 00b6
0000050: 002d a700 06a7 0003 b1
Stackmap Table:
append_frame(@9,Object[#2],Integer)
same_frame(@44)
append_frame(@65,Object[#31])
chop_frame(@70,1)
same_frame(@85)
chop_frame(@88,2)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:537)
at java.base/java.lang.Class.forName(Class.java:516)
at jdk.compiler/com.sun.tools.javac.launcher.Main.execute(Main.java:432)
at jdk.compiler/com.sun.tools.javac.launcher.Main.run(Main.java:208)
at jdk.compiler/com.sun.tools.javac.launcher.Main.main(Main.java:135)
- backported by
-
JDK-8322396 Non-verifiable code is emitted when two guards declare pattern variables in colon-switch
- Resolved
-
JDK-8323207 Non-verifiable code is emitted when two guards declare pattern variables in colon-switch
- Resolved
- relates to
-
JDK-8314226 Series of colon-style fallthrough switch cases with guards compiled incorrectly
- Resolved
- links to
-
Commit openjdk/jdk21u-dev/03acee85
-
Commit openjdk/jdk/15588e08
-
Review openjdk/jdk21u-dev/26
-
Review openjdk/jdk/15630
(2 links to)