RFR: 8334043: VerifyError when inner class is accessed in prologue

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Jun 13 21:15:12 UTC 2024


On Tue, 11 Jun 2024 21:10:37 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

> The new flexible constructors logic creates an exception to the normal rule preventing early access to `this` in an early construction context by allowing assignments to instance fields. The check for this exception is performed by `Resolve.isAllowedEarlyReference()`, but this method was incorrectlly assuming that the expression was simpler than it can sometimes be, for example, for more complicated assignment expressions like `this.new InnerClass().foo = 123`.
> 
> This change verifies that the expression actually looks like either `Y = Z` or `X.Y = Z` where `X` is a simple reference to the current class' `this` instance (i.e., `this`, or `ThisClass.this`).

Marked as reviewed by mcimadamore (Reviewer).

> > The fix seems too strict? E.g. something like this is legal, I believe:
> > ```java
> > class A {
> >    Object o;
> >    A() { A.this.o = "Hello"; }
> > }
> > ```
> 
> That compiles, and so does this (which puts the assignment in an early construction context):
> 
> ```java
> class A {
>   Object o;
>   A() {
>     A.this.o = "Hello";
>     super();
>   }
> }
> ```
> 
> If you're getting at the `A.this` vs. `this` question, that's what `TreeInfo.isExplicitThisReference()` is there to handle.
> 
> I could be missing what you're getting at, if so let me know.

Thanks for the explanation. I didn't double check what `isExplicitThisReference` did, and I erroneously assumed it checked for `this` only.

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

PR Review: https://git.openjdk.org/jdk/pull/19666#pullrequestreview-2117042856
PR Comment: https://git.openjdk.org/jdk/pull/19666#issuecomment-2166804115


More information about the compiler-dev mailing list