RFR: 8043179: Lambda expression can mutate final field [v3]

Archie L. Cobbs duke at openjdk.org
Sun Sep 25 21:06:32 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).

Archie L. Cobbs has updated the pull request incrementally with two additional commits since the last revision:

 - Move unit test into a more appropriate subdirectory.
 - Use /nodynamiccopyright/ for "golden file" test per instructions.

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/10381/files
  - new: https://git.openjdk.org/jdk/pull/10381/files/47df9c96..6ae0fca3

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

  Stats: 54 lines in 4 files changed: 16 ins; 38 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