RFR: 8334043: VerifyError when inner class is accessed in prologue
Archie Cobbs
acobbs at openjdk.org
Wed Jun 12 15:55:13 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`).
> 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):
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.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/19666#issuecomment-2163391100
More information about the compiler-dev
mailing list