The treatment of break and continue in the description of reachability
in the JLS is confusing and contradictory. Specifically, the assignment
statement below is considered reachable:
int i;
a: try {
break a;
} finally {
return;
}
i = 12; // reachable?
It is reachable because the break statement is reachable and "there
is a reachable break statement that exits the labeled statement".
On the other hand, what does it mean "exits the labeled statement"?
Certainly the break statement refers to the labelled statement, but
because of the intervening finally block that cannot complete normally,
it will never cause control to transfer to the statements following the
labelled statement.
A clarification is in order for the meaning of when a break statment
"exits the labeled statement". A similar clarification is needed for
the continue statement.
Two possible but different clarifications might be
(1) a break statement exits the statment if it is matched with that statement
by the description in 14.14 AND every intervening finally clause can complete
normally; or
(2) a break statement exits the statment if it is matched with that statement
by the description in 14.14 (whether or not intervening finalizers can
complete normally)
Either way we go, we should be explicit in our choice and call the reader's
attention to the issue so there is no further confusion on the intended
meaning.
A large number of javac failures on the jacks test suite boil down to this
specification question.
in the JLS is confusing and contradictory. Specifically, the assignment
statement below is considered reachable:
int i;
a: try {
break a;
} finally {
return;
}
i = 12; // reachable?
It is reachable because the break statement is reachable and "there
is a reachable break statement that exits the labeled statement".
On the other hand, what does it mean "exits the labeled statement"?
Certainly the break statement refers to the labelled statement, but
because of the intervening finally block that cannot complete normally,
it will never cause control to transfer to the statements following the
labelled statement.
A clarification is in order for the meaning of when a break statment
"exits the labeled statement". A similar clarification is needed for
the continue statement.
Two possible but different clarifications might be
(1) a break statement exits the statment if it is matched with that statement
by the description in 14.14 AND every intervening finally clause can complete
normally; or
(2) a break statement exits the statment if it is matched with that statement
by the description in 14.14 (whether or not intervening finalizers can
complete normally)
Either way we go, we should be explicit in our choice and call the reader's
attention to the issue so there is no further confusion on the intended
meaning.
A large number of javac failures on the jacks test suite boil down to this
specification question.
- relates to
-
JDK-4088988 JLS3 14.21 Not detecting unreachable code (exit via break with intervening finally block)
- Closed