-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
P4
-
Affects Version/s: 25, 26
-
Component/s: specification
As a followup to JEP 513, there are some inconsistencies between how the spec treats unqualified field references vs. those qualified with 'this' or 'super'.
In 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.
The specific 6.5.6.1 restrictions for instance field references are:
1) Not in a static context.
2) In early construction, the reference is the LHS of an assignment.
3) In early construction, the field has no initializer.
4) In early construction, does not appear in a nested class declaration, or in a lambda expression
5) In early construction, the field is not declared by a superclass.
6) Either the field is a member of the current class, or the current class is an inner class of the field's class.
In 15.8.3 ('this.x'), (1), (2), and (4) are enforced, and (6) is irrelevant. But there are no rules enforcing (3) and (5).
In 15.8.4 ('C.this.x'), (1), (2), (4), and (6) are enforced. Again, rules for (3) and (5) are missing.
In 15.11.2 ('super.x', 'C.super.x'), (1) and (6) are enforced, and any references from early construction would violate (5). However, the specific rule about early construction seems off: it refers to "an early construction context of the current class", when the relevant question is whether the reference is in an early construction context of *C*.
See also JDK-8368719, which proposes an adjusted structure to 6.5.6.1 that may be useful to adopt with this bug fix.
In 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.
The specific 6.5.6.1 restrictions for instance field references are:
1) Not in a static context.
2) In early construction, the reference is the LHS of an assignment.
3) In early construction, the field has no initializer.
4) In early construction, does not appear in a nested class declaration, or in a lambda expression
5) In early construction, the field is not declared by a superclass.
6) Either the field is a member of the current class, or the current class is an inner class of the field's class.
In 15.8.3 ('this.x'), (1), (2), and (4) are enforced, and (6) is irrelevant. But there are no rules enforcing (3) and (5).
In 15.8.4 ('C.this.x'), (1), (2), (4), and (6) are enforced. Again, rules for (3) and (5) are missing.
In 15.11.2 ('super.x', 'C.super.x'), (1) and (6) are enforced, and any references from early construction would violate (5). However, the specific rule about early construction seems off: it refers to "an early construction context of the current class", when the relevant question is whether the reference is in an early construction context of *C*.
See also JDK-8368719, which proposes an adjusted structure to 6.5.6.1 that may be useful to adopt with this bug fix.
- relates to
-
JDK-8368719 6.5.6.1: Shouldn't allow field references before 'this()'
-
- Open
-
-
JDK-8344702 JEP 513: Flexible Constructor Bodies
-
- Closed
-
-
JDK-8373721 [lworld] value-objects-jls: fix JLS rules for this-qualified field accesses
-
- Open
-