RFR: 8305007: Within-lambda subclass of local class using method param causes compiler crash

ExE Boss duke at openjdk.org
Thu Apr 18 18:38:58 UTC 2024


On Mon, 18 Dec 2023 23:38:26 GMT, Vicente Romero <vromero at openjdk.org> wrote:

> javac is crashing while compiling code like:
> 
> 
> public abstract class CompilerCrashLambdaPlusLocalClass {
>     public abstract void consume(Runnable r);
> 
>     public void doThing(String parameter) {
>         class LocalClass {
>             @Override
>             public String toString() {
>                 return parameter;
>             }
>         }
>         consume(() -> {
>             class LambdaLocalClass extends LocalClass {}
>             new LocalClass();
>         });
>     }
> }
> 
> the reason for the issue is that the mappings for captured variables created by LambdaToMethod are not copying the `adr`, local address, field of the original VarSymbol it is mapping. Later on during code generation an assertion was being triggered due to a variable with an `adr < 0` this patch fixes this issue.
> 
> Thanks,
> Vicente

test/langtools/tools/javac/lambda/CompilerCrashLambdaPlusLocalClass.java line 43:

> 41:         consume(() -> {
> 42:             class LambdaLocalClass extends LocalClass {}
> 43:             new LocalClass();

Shouldn’t this construct a `LambdaLocalClass` instance instead?
Suggestion:

            new LambdaLocalClass();

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17151#discussion_r1435405123


More information about the compiler-dev mailing list