Details
-
Bug
-
Resolution: Fixed
-
P5
-
1.4.0
-
generic
-
solaris_8
Description
JLS 16.2.11 has a problem with ForUpdate statements. The
following program gives a compile-time error with javac:
class C {
void bar() {
for (final int i; 0 < (i = 1); i = i + 1)
break;
}
}
Yet the current wording in the JLS permits it as legal. i is DU after
the init part, i is both DA and DU after the contained break, and there
are no continue statements; therefore i is DU before the condition
expression (16.2.11.d) and may be assigned there. Further, since i is
both DA and DU after the contained break, and there are no continue
statements, the increment statement is not violating either rule that a
variable must be DA before access or DU before assignment. Compare this
to a program with similar semantics, which does compile:
class D {
void bar() {
final int i;
label:
if (0 < (i = 1)) {
if (true)
break label;
i = i + 1;
}
}
}
following program gives a compile-time error with javac:
class C {
void bar() {
for (final int i; 0 < (i = 1); i = i + 1)
break;
}
}
Yet the current wording in the JLS permits it as legal. i is DU after
the init part, i is both DA and DU after the contained break, and there
are no continue statements; therefore i is DU before the condition
expression (16.2.11.d) and may be assigned there. Further, since i is
both DA and DU after the contained break, and there are no continue
statements, the increment statement is not violating either rule that a
variable must be DA before access or DU before assignment. Compare this
to a program with similar semantics, which does compile:
class D {
void bar() {
final int i;
label:
if (0 < (i = 1)) {
if (true)
break label;
i = i + 1;
}
}
}
Attachments
Issue Links
- relates to
-
JDK-4718379 16.2.5: Clarify DU/DA for labeled statements with break
-
- Open
-
-
JDK-8198245 javac is incorrectly implementing the DA/DU rules for for-loops
-
- Resolved
-