RFR: 8372635: Lambdas do not copy over SYNTHETIC flag for local variables [v2]

Jan Lahoda jlahoda at openjdk.org
Thu Dec 11 13:58:28 UTC 2025


> 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.

Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:

  Copy all flags when creating lambda local var/parameter.

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/28724/files
  - new: https://git.openjdk.org/jdk/pull/28724/files/28cda46f..9aa6642a

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=28724&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=28724&range=00-01

  Stats: 3 lines in 1 file changed: 1 ins; 0 del; 2 mod
  Patch: https://git.openjdk.org/jdk/pull/28724.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/28724/head:pull/28724

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


More information about the compiler-dev mailing list