According to spec bugs: JDK-8373719 and JDK-8373721:

In JLS 6.5.6.1, references to fields are subject to a handful of restrictions 
if they refer to instance fields. In 15.8 and 15.11, 'this.x' and 'super.x' are 
intended to be viewed as instance field references, and subject to the same 
restrictions.

So the following code should fail to compile:

class Test {
    static final boolean check = true;
    Test(int a) {
        boolean b = Test.this.check; //compilation error expected here
        this();
    }
}

However, javac is currently accepting it

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

Commit messages:
 - 8373916: [lworld] TypeName.this.FieldName should be restricted in early 
construction context

Changes: https://git.openjdk.org/valhalla/pull/1899/files
  Webrev: https://webrevs.openjdk.org/?repo=valhalla&pr=1899&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8373916
  Stats: 36 lines in 6 files changed: 33 ins; 0 del; 3 mod
  Patch: https://git.openjdk.org/valhalla/pull/1899.diff
  Fetch: git fetch https://git.openjdk.org/valhalla.git pull/1899/head:pull/1899

PR: https://git.openjdk.org/valhalla/pull/1899

Reply via email to