Switch-expression with nested try
Tagir Valeev
amaembo at gmail.com
Tue Nov 20 09:49:02 UTC 2018
Hello!
Switch expression with nested try is a weird beast. I was wondering
how you managed to compile it. Seems it's still problematic. Code:
public class Java12Test {
public static void main(String[] args) {
System.out.println(switch(0) {
default -> {
try { throw new Exception(); }
catch(Exception ex) {
break 1;
}
}
});
}
}
>"C:\Program Files\Java\jdk-12\bin\java.exe" -version
openjdk version "12-ea" 2019-03-19
OpenJDK Runtime Environment (build 12-ea+20)
OpenJDK 64-Bit Server VM (build 12-ea+20, mixed mode, sharing)
>"C:\Program Files\Java\jdk-12\bin\javac.exe" --enable-preview --release=12 Java12Test.java
Note: Java12Test.java uses preview language features.
Note: Recompile with -Xlint:preview for details.
>"C:\Program Files\Java\jdk-12\bin\java.exe" --enable-preview Java12Test
Error: Unable to initialize main class Java12Test
Caused by: java.lang.VerifyError: Stack map does not match the one at
exception handler 24
Exception Details:
Location:
Java12Test.main([Ljava/lang/String;)V @16: new
Reason:
Current frame's stack size doesn't match stackmap.
Current Frame:
bci: @16
flags: { }
locals: { '[Ljava/lang/String;' }
stack: { 'java/lang/Exception' }
Stackmap Frame:
bci: @24
flags: { }
locals: { '[Ljava/lang/String;' }
stack: { 'java/io/PrintStream', 'java/lang/Exception' }
Bytecode:
0000000: b200 0203 ab00 0000 0000 000c 0000 0000
0000010: bb00 0359 b700 04bf 4d04 3ca7 0003 1bb6
0000020: 0005 b1
Exception Handler Table:
bci [16, 24] => handler: 24
Stackmap Table:
same_locals_1_stack_item_frame(@16,Object[#15])
full_frame(@24,{Object[#16]},{Object[#15],Object[#3]})
full_frame(@30,{Object[#16],Integer},{Object[#15]})
With best regards,
Tagir Valeev
More information about the compiler-dev
mailing list