RFR: 8328649: Disallow enclosing instances for local classes in constructor prologues [v2]
Archie Cobbs
acobbs at openjdk.org
Thu Apr 4 14:31:28 UTC 2024
> A local class declared in a static context is not supposed to have an immediately enclosing instance (§15.9.2). That includes local classes declared in constructors prior to `super()` (during the "constructor prologue" in the new lingo).
>
> However, the compiler is allowing code like this to successfully compile:
>
> import java.util.concurrent.atomic.*;
> public class Test extends AtomicReference<Object> {
>
> public Test() {
> super(switch (0) {
> default -> {
> class Local { { Test.this.hashCode(); } } // this should fail
> yield null;
> }
> });
> }
> }
>
> This patch fixes the "leak".
Archie Cobbs has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:
- Merge branch 'master' into JDK-8328649
- Remove obsolete test cases.
- No enclosing instance for local classes in constructor prologues.
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/18416/files
- new: https://git.openjdk.org/jdk/pull/18416/files/d98cb3d5..c9d399d7
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=18416&range=01
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=18416&range=00-01
Stats: 357608 lines in 2856 files changed: 17713 ins; 14957 del; 324938 mod
Patch: https://git.openjdk.org/jdk/pull/18416.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/18416/head:pull/18416
PR: https://git.openjdk.org/jdk/pull/18416
More information about the compiler-dev
mailing list