JDK-6865521 : "Arrays.asList()" gets unchecked warning
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2009-07-28
  • Updated: 2011-02-16
  • Resolved: 2009-07-28
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
javac 1.6.0_07
javac 1.5.0_16

ADDITIONAL OS VERSION INFORMATION :
Linux 2.6.18-92.1.22.el5
Mac OS X 10.5.6

A DESCRIPTION OF THE PROBLEM :
A simple, no-argument invocation of Arrays.asList prompts an unchecked warning.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the given code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No warnings.  (Expected behavior occurs in Eclipse.)  The compiler should infer that T = Object and determine that an empty Object[] must be allocated for the invocation.
ACTUAL -
A warning occurs.  The compiler seems to have failed to substitute Object for T before verifying that the varargs arguments have a reifiable type.  Note that the error message makes no sense -- the type "T[]" is meaningless in the calling context.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
EmptyAsList.java:3: warning: [unchecked] unchecked generic array creation of type T[] for varargs parameter
    java.util.Arrays.asList();
                           ^

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class EmptyAsList {
  public static void main(String... args) {
    java.util.Arrays.asList();
  }
}


---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Provide an explicit type argument: Arrays.<Object>asList()

Comments
EVALUATION This is a duplicate of 6730476 - type variables inferred during 15.12.2.8 aren't substituted into formals before the generic array creation check occurs.
28-07-2009