class B {
static final int x;
static { while (true) {} }
static { x = 1; }
}
==>
Init4.java:4: Statement not reached.
static { x = 1; }
^
Init4.java:4: Can't assign a second value to a blank final variable: x
static { x = 1; }
^
---
The second error message is incorrect. Clearly, 'x' has not been previously
assigned, and any reasonable definition of "definite unassignment"
(unfortunately not formally defined in the JLS or the current inner class
specification) would recognize this.
The first error message should not have been issued according to the JLS, but
the statment is in fact unreachable and will be detected as such in the course
of the definite assignment/unassingment analysis whether the error message is
issued or not. A separate bug report has been filed for this, 4063938.
static final int x;
static { while (true) {} }
static { x = 1; }
}
==>
Init4.java:4: Statement not reached.
static { x = 1; }
^
Init4.java:4: Can't assign a second value to a blank final variable: x
static { x = 1; }
^
---
The second error message is incorrect. Clearly, 'x' has not been previously
assigned, and any reasonable definition of "definite unassignment"
(unfortunately not formally defined in the JLS or the current inner class
specification) would recognize this.
The first error message should not have been issued according to the JLS, but
the statment is in fact unreachable and will be detected as such in the course
of the definite assignment/unassingment analysis whether the error message is
issued or not. A separate bug report has been filed for this, 4063938.
- relates to
-
JDK-4063938 Compiler reports unreachable static initializers, contrary to JLS
-
- Closed
-