Bug 133292 - [compiler] Compiler accepts spurious semicolon in array initialiser
Summary: [compiler] Compiler accepts spurious semicolon in array initialiser
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.2 M6   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-26 06:15 EST by Mike Spivey CLA
Modified: 2006-03-28 10:25 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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