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?
> 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?
- relates to
-
JDK-8289777 javac does not see a problem when Eclipse emits a 'blank final field may not have been initialized' error
- Closed
- links to
-
Review openjdk/jdk/10956