Community
Participate
Working Groups
public class Foo { /* On the next line, the first semicolon is a syntax error. * The error is not reported, and the program will run and print "Fail". * Without the semicolon, it prints "foo" as expected. */ public static Baz.C a[] = { new Baz.C("foo") ; }; public static void main(String args[]) { if (a == null) System.out.println("Fail"); else System.out.println(a[0]); } } class Baz { public static class C { String name; public C(String name) { this.name = name; } public String toString() { return name; } } }
I'll investigate.
Reduce test case: public class X { java.lang.Object o[] = { new String("SUCCESS") ; }; } If the type of the field is not qualified, the compiler reports an error. The array initializer is wrongly seen as an initializer. I'll check the grammar. We might have a bug there.
David, The syntax error is detected, but we eat it silently in the recovery.
The problem is inside RecoveredField#updateOnOpeningBrace() This method check if the type of the field is an ArrayTypeReference but doesn't check if the type is ArrayQualifiedTypeReference. There is the same problem if RecoveredLocalVariable.
Fixed and tests added SyntaxErrorTest#test07() -> test10()
Verified using I20060328-0010 for 3.2M6