Integrated: 8372635: Lambdas do not copy over SYNTHETIC flag for local variables

Jan Lahoda jlahoda at openjdk.org
Wed Dec 17 07:26:04 UTC 2025


On Tue, 9 Dec 2025 15:04:42 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> Consider case like:
> 
> Object o = ...;
> 
> //synthetic variable for the instanceof's expression
> boolean b = o.toString() instanceof String str && str.isEmpty();
> 
> Runnable r = () -> {
>         //synthetic variable for the instanceof's expression
>         boolean b = o.toString() instanceof String str && str.isEmpty();
> };
> 
> 
> There are synthetic variables generated for `o.toString()`, to ensure the method is invoked only once for each `instanceof`. These variables are marked as synthetic in `TransPatterns` (and then consequently omitted in `LocalVariableTable`), but when the flag is lost for the variable in the lambda.
> 
> This PR proposes to keep the flag, as suggested in the bug.

This pull request has now been integrated.

Changeset: 94c51ce3
Author:    Jan Lahoda <jlahoda at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/94c51ce314eea7a4f188fa0db1bae0e3f3dbd230
Stats:     141 lines in 2 files changed: 139 ins; 0 del; 2 mod

8372635: Lambdas do not copy over SYNTHETIC flag for local variables

Reviewed-by: vromero, liach

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

PR: https://git.openjdk.org/jdk/pull/28724


More information about the compiler-dev mailing list