RFR: 8322882: Null pointer error when compiling Static initializer in a local class
Maurizio Cimadamore
mcimadamore at openjdk.org
Tue Jun 18 23:24:11 UTC 2024
On Tue, 18 Jun 2024 14:59:52 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> Looking closer, this seems another specification issue. I don't see anything in the JLS draft ruling this out (as, per JLS, `Local` has no enclosing instance). Reached out to Gavin/Dan.
It is indeed a spec bug. The intended behavior is that a local class can only be created from a context in which a local variable declared beside the local class is also accessible. So, `Local` here is in the same scope as `there`. But `there` is not accessible from the static initializer of Local, so that's an error.
Of course the analysis should not attempt to reason about captured variables, but instead should try to walk back from the current `env` to the `env` of the target local class, and if any `static` context is crossed during the traversal, an error should be issued.
If you want you can take a stab at implementing this check.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/19754#issuecomment-2177242809
More information about the compiler-dev
mailing list