Bug 133292

Summary: [compiler] Compiler accepts spurious semicolon in array initialiser
Product: [Eclipse Project] JDT Reporter: Mike Spivey <mike>
Component: CoreAssignee: David Audel <david_audel>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.2 M6   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Mike Spivey CLA 2006-03-26 06:15:20 EST
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; }
    }
}
Comment 1 Olivier Thomann CLA 2006-03-26 11:56:59 EST
I'll investigate.
Comment 2 Olivier Thomann CLA 2006-03-26 20:47:53 EST
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.
Comment 3 Olivier Thomann CLA 2006-03-27 09:46:51 EST
David,

The syntax error is detected, but we eat it silently in the recovery.
Comment 4 David Audel CLA 2006-03-27 11:44:25 EST
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.
Comment 5 David Audel CLA 2006-03-27 11:49:00 EST
Fixed and tests added
  SyntaxErrorTest#test07() -> test10()

Comment 6 Olivier Thomann CLA 2006-03-28 10:25:10 EST
Verified using I20060328-0010 for 3.2M6