Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8204693

8.3.3: Disallow forward reference to a field by a qualified name using 'this'

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 11
    • Fix Version/s: tbd_major
    • Component/s: specification
    • Labels:

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                abuckley Alex Buckley
                Reporter:
                abuckley Alex Buckley
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: