Community
Participate
Working Groups
Build I20071120-0800. Eclipse does not flag any error on following test case: package bug; public class Test { static int X; String field = { String str; switch (X) { case 0: str = "zero"; break; default: str = "other"; break; } this.field = str; }; public static void main(String[] args) { System.out.println(new Test().field); } } You can even run it and get a "zero" in the console. javac 1.4.2 report following errors: java version "1.4.2_16" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_16-b05) Java HotSpot(TM) Client VM (build 1.4.2_16-b05, mixed mode) test005\Test.java:5: '}' expected String str; ^ test005\Test.java:6: illegal start of type switch (X) { ^ test005\Test.java:14: <identifier> expected this.field = str; ^ test005\Test.java:16: 'class' or 'interface' expected public static void main(String[] args) { ^ test005\Test.java:19: 'class' or 'interface' expected } ^ test005\Test.java:20: 'class' or 'interface' expected ^ 6 errors
Not a regression as this happened at least since 3.1.2...
If error diagnosis cannot infer anything, then as a fall-back approach, the original (ugly) syntax error should be reinjected back. Separately from that, the diagnosis shouldn't fail to produce a diagnosis.
This problem is not reproducible on HEAD: Here are the errors I get: Description Resource Path Location Type Syntax error on token ";", { expected after this token Test.java /_pasted_code_/src line 4 Java Problem Syntax error on token "(", ; expected Test.java /_pasted_code_/src line 15 Java Problem Syntax error on token ")", ; expected Test.java /_pasted_code_/src line 15 Java Problem Syntax error on token "}", delete this token Test.java /_pasted_code_/src line 14 Java Problem Syntax error on token "default", invalid Label Test.java /_pasted_code_/src line 9 Java Problem Syntax error on token(s), misplaced construct(s) Test.java /_pasted_code_/src line 3 Java Problem Syntax error on tokens, Label expected instead Test.java /_pasted_code_/src line 6 Java Problem Syntax error, insert "}" to complete ClassBody Test.java /_pasted_code_/src line 18 Java Problem I'll add a regression test and close this as WORKSFORME.
Created attachment 173618 [details] Proposed regression test
Released regression tests on HEAD for 3.7 M1.
Verified for 3.7M1 using build I20100802-1800.