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

Archie L. Cobbs duke at openjdk.org
Sun Sep 25 00:30:05 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 refreshed the contents of this pull request, and previous commits have been removed. The incremental views will show differences compared to the previous content of the PR. The pull request contains one new commit since the last revision:

  8043179: Lambda expression can mutate final field

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

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

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

  Stats: 52 lines in 5 files changed: 46 ins; 4 del; 2 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