Bug 78049 - [1.5][compiler] Missed error for generic array creation.
Summary: [1.5][compiler] Missed error for generic array creation.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows 2000
: P3 minor (vote)
Target Milestone: 3.1 M4   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-08 01:12 EST by R Lenard CLA
Modified: 2004-12-14 15:46 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 R Lenard CLA 2004-11-08 01:12:11 EST
I read somewhere that creation of generic arrays is not allowed and the results 
of JAVAC seem to confirm this.
% cat X.java
public class X
{
    public static void main(String[] args) {
        Comparable<String>[] X = {
        };
        System.err.println("X.toString() " + X.toString());

        Comparable<String>[] Y = new Comparable<String>[] {
        };
     }
}
% javac X.java
c:/Eclipse/Fooey/src/X.java:4: generic array creation
        Comparable<String>[] X = {
                                 ^
c:/Eclipse/Fooey/src/X.java:8: generic array creation
        Comparable<String>[] Y = new Comparable<String>[] {
                                                          ^
2 errors

However 3.1M3 doesn't detect the first as a problem.
Comment 1 Philipe Mulet CLA 2004-11-08 06:45:23 EST
Array initializers of generic array type should indeed be rejected (currently
only rejecting array alloc expr).

Added regression test: GenericTypeTest#test393. Tricky case is array alloc
combined with trailing initializer, should only issue one error report:
e.g. new List<String[]{}

Fixed
Comment 2 Olivier Thomann CLA 2004-12-14 15:46:55 EST
Verified in 200412140800