Community
Participate
Working Groups
In the case of multiple label before a loop statement (for, do, while), if there is a continue statement with a label identifier which not represent the label just before the loop statement, the compiler should generate a compilation error. Example: public class Test { public static void main(String[] args) { a : b : for (int i= 0; i < 10; i++) { if (i % 2 == 0) continue b; if (i % 2 == 1) continue a; } } } see the Java Language Spec, §14.15 "A continue statement with label Identifier attempts to transfer control to the enclosing labeled statement (§14.7) that has the same Identifier as its label; that statement, which is called the continue target, then immediately ends the current iteration and begins a new one. The continue target must be a while, do, or for statement or a compile-time error occurs. (...)" javac generate the correct error: > javac Test.java Test.java:7: not a loop label: a continue a; ^ 1 error
Good find.
Note that javac 1.3.1 did allow such code.
Fixed (LabelStatement#concreteStatement()).
Verified.