Integrated: 8328649: Disallow enclosing instances for local classes in constructor prologues
Archie Cobbs
acobbs at openjdk.org
Thu Apr 4 21:17:05 UTC 2024
On Thu, 21 Mar 2024 02:10:09 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:
> 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".
This pull request has now been integrated.
Changeset: d80d4781
Author: Archie Cobbs <acobbs at openjdk.org>
Committer: Vicente Romero <vromero at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/d80d4781828d68c498831cddf9782055dda472d1
Stats: 69 lines in 5 files changed: 36 ins; 29 del; 4 mod
8328649: Disallow enclosing instances for local classes in constructor prologues
Reviewed-by: vromero
-------------
PR: https://git.openjdk.org/jdk/pull/18416
More information about the compiler-dev
mailing list