Bug 105801 - [1.5][compiler] Too many warnings for non-matching types of arguments of varargs call
Summary: [1.5][compiler] Too many warnings for non-matching types of arguments of vara...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.2 M6   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-02 10:57 EDT by Markus Keller CLA
Modified: 2006-03-28 06:39 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 Markus Keller CLA 2005-08-02 10:57:24 EDT
I20050726-1222

Too many warnings for non-matching types of arguments of varargs call:
- varargs(new Object[] {1, 2}) warns, but shouldn't
- varargs((Serializable) new Serializable[] {3, 4}) warns, but shouldn't

See inlined explanations:

import java.io.Serializable;
import java.util.Arrays;

public class Try {
    static void array(Serializable... items) {
        System.out.println(Arrays.deepToString(items));
    }
    static void varargs(Serializable... items) {
        System.out.println(Arrays.deepToString(items) + " (argument wrapped)");
    }

    public static void main(String[] args) {
        varargs(new Object[] {1, 2}); //warns "Varargs argument Object[]
            //should be cast to Serializable[] ..", but proposed cast to
            //Serializable[] fails at run time (javac does not warn here)
        array(new Serializable[] {3, 4});
        array(new Integer[] {5, 6}); //warns (as javac does)
        array(null); //warns (as javac does)
        
        varargs((Serializable) new Object[] {1, 2});
        varargs((Serializable) new Serializable[] {3, 4}); //warns about
            //unnecessary cast, although cast is necessary (causes varargs call)
        varargs((Serializable) new Integer[] {5, 6});
        varargs((Serializable) null);
        
        array((Serializable[]) new Serializable[] {3, 4}); //warns about
            //unnecessary cast
        array((Serializable[]) new Integer[] {5, 6});
        array((Serializable[]) null);
        array((Serializable[]) new Object[] {1, 2}); // CCE at run time
    }
}
Comment 1 Philipe Mulet CLA 2006-03-06 04:50:56 EST
Added VarargsTest#test038-045.

Tuned the reporting for unnecessary cast and need for varargs cast to address these discrepancies. Thanks for the excellent testcases.

Fixed
Comment 2 David Audel CLA 2006-03-28 06:39:13 EST
Verified for 3.2 M6 using build I20060328-0010