RFR: 8043179: Lambda expression can mutate final field.

Archie L. Cobbs duke at openjdk.org
Wed Sep 21 23:12:52 UTC 2022


This patch causes lambdas to be treated like non-constructor methods with respect to field initialization in `Flow.AssignAnalyzer`.

This fixes [JDK-8043179](https://bugs.openjdk.org/browse/JDK-8043179); the test program in the bug now gives this:

LambdaFieldInit.java:6: error: variable x might already have been assigned
        Runnable r1 = () -> x = "hi";
                            ^


This also aligns the compiler with the proposed spec fix in [JDK-8043176](https://bugs.openjdk.org/browse/JDK-8043176) and fixes the inconsistency between lambdas and inner class methods shown [here](https://stackoverflow.com/questions/39881295/why-are-java-lambdas-treated-differently-from-nested-classes-with-respect-to-ins).

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

Commit messages:
 - 8043179: Lambda expression can mutate final field.

Changes: https://git.openjdk.org/jdk/pull/10381/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=10381&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8043179
  Stats: 3 lines in 1 file changed: 3 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/10381.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/10381/head:pull/10381

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


More information about the compiler-dev mailing list