JDK-8204693 : 8.3.3: Disallow forward reference to a field by a qualified name using 'this'
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 11
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2018-06-11
  • Updated: 2018-06-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbd_majorUnresolved
Related Reports
Relates :  
Relates :  
Description
In 16.0, DU/DA analysis defines access to a blank final field as consisting "of the simple name of the variable (or, for a field, the simple name of the field qualified by this)". However, in 8.3.3, a forward reference to a field by an instance variable initializer or instance initializer is caught only by simple name. For consistency, it may be desirable for 8.3.3 to also catch forward references of the form 'this.f':

"For a reference to an instance variable f declared in class C, ***where the reference is either the simple name `f` or the qualified name `this.f`,*** it is a compile-time error if:"

"For a reference to a class variable f declared in class or interface C, ***where the reference is either the simple name `f` or the qualified name `C.f`,*** it is a compile-time error if:"

See http://mail.openjdk.java.net/pipermail/compiler-dev/2018-June/012011.html. Note that these restrictions are easy to work around (just alias `g` to `this`, and access `g.f`), but the thrust of 8.3.3 is that obviously malformed initializations should be prevented.

As a technical matter, 16.0 and 8.3.3should clarify that parentheses around the simple name `f`, or the qualified name `this.f`, or the primary `this` in the qualified name `this.f`, do not affect the rules. See http://mail.openjdk.java.net/pipermail/compiler-dev/2018-June/012014.html.