Community
Participate
Working Groups
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 } }
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
Verified for 3.2 M6 using build I20060328-0010