Uninitialized final field access and qualified this

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: P4
    • tbd
    • Affects Version/s: 9
    • Component/s: tools
    • None

      JLS 9 §16 includes:

      > Each local variable (§14.4) and every blank final field (§4.12.4, §8.3.1.2) must have a definitely assigned value when any access of its value occurs.

      > An access to its value consists of the simple name of the variable (or, for a field, the simple name of the field qualified by this) occurring anywhere in an expression except as the left-hand operand of the simple assignment operator = (§15.26.1).

      javac 9.0.1+11 rejects uninitialized accesses like the following, as expected:

      class A {
        final int x;
        A() {
          System.err.println(x); // x might not have been initialized
          System.err.println(this.x); // x might not have been initialized
          x = 42;
        }
      }

      However it accepts accesses using qualified this, e.g.:

      class A {
        final int x;
        A() {
          System.err.println(A.this.x);
          x = 42;
        }
      }

      Should accesses to fields using qualified this be rejected?

            Assignee:
            Vicente Arturo Romero Zaldivar
            Reporter:
            Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: