Withdrawn: 8193904: Uninitialized final field access and qualified this

Archie L. Cobbs duke at openjdk.org
Tue Dec 6 14:39:15 UTC 2022


On Wed, 2 Nov 2022 19:04:45 GMT, Archie L. Cobbs <duke at openjdk.org> wrote:

> If a class `MyClass` has a blank final field `foo` that has not yet been assigned, the compiler prevents you from accessing it via the expressions `foo` or `this.foo`. However, it does not prevent you from accessing it via the expression `MyClass.this.foo`.
> 
> Here's a simple example:
> 
> class QualifiedThis {
>     final int foo;
>     QualifiedThis() {
>         System.err.println(QualifiedThis.this.foo);   // should get an error here
>         this.foo = 42;
>     }
> }
> 
> 
> This patch fixes that omission.
> 
> I couldn't find an existing method that answers the question "Is this AST tree a reference to the current instance of the class I'm now compiling?" so I wrote a new one `TreeInfo.isThisReference()`.
> 
> The question itself is a little tricky. For example, `this` alone always is, but `Foo.this` is if the class being compiled is `Foo` or any supertype of `Foo`, *except* when `Foo` is an outer class containing the class being compiled, when it instead refers to that outer instance.
> 
> On the other hand, `Foo.super` (which, unlike `Foo.this`, can only be used to invoke a method), when `Foo` is a type and not a variable, refers to the current 'this' instance when the class being compiled is `Foo` or any supertype of `Foo`, period.

This pull request has been closed without being integrated.

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

PR: https://git.openjdk.org/jdk/pull/10956


More information about the compiler-dev mailing list