RFR: 8315735: VerifyError when switch statement used with synchronized block [v2]

ExE Boss duke at openjdk.org
Wed Sep 6 19:19:45 UTC 2023


On Wed, 6 Sep 2023 18:58:19 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

>> Having code like:
>> 
>>     public static void main(String... args) {
>>         int i1 = 0 + switch (args.length) {
>>             default -> {
>>                 synchronized (args) {
>>                     yield 1;
>>                 }
>>             }
>>         };
>>     }
>> 
>> 
>> fails with a verification error at runtime. In the classfile, the synchronized block is basically a try-finally (which has an implicit "catch (any)" block), and so it needs the same handling as ordinary try statements.
>> 
>> (When there's a try statement inside a switch expression, the pre-existing stack is stored in local variables, and restored at return from the case. This is because catch clauses start with an empty stack.)
>
> Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Reflecting review feedback.

src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java line 1281:

> 1279:     //where:
> 1280:         private boolean hasTry(JCSwitchExpression tree) {
> 1281:             var scan = new TreeScanner() {

I think `scanner` might be a better name for this:
Suggestion:

            var scanner = new TreeScanner() {

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/15584#discussion_r1317721431


More information about the compiler-dev mailing list