JDK-6865519 : Incorrect unchecked warning involving local class
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6u14
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: linux
  • CPU: x86
  • Submitted: 2009-07-28
  • Updated: 2011-02-16
  • Resolved: 2009-07-28
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
javac 1.6.0_14-b08)


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

A DESCRIPTION OF THE PROBLEM :
I get an unchecked warning when an assignment conversion from a non-parameterized local class type to a parameterized supertype occurs.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the program below.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should compile without warning.
ACTUAL -
Produces an unchecked warning.  Note that only the local class type leads to a warning; the identical member class does not cause a warning.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
NoTypeArg.java:8: warning: [unchecked] unchecked conversion
found   : Instance2
required: NoTypeArg.Foo<T>
    f = new Instance2(); // unchecked warning
 

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class NoTypeArg<T> {
  interface Foo<T> {}
  class Instance1 implements Foo<T> {}
  public void method() {
    class Instance2 implements Foo<T> {}
    Foo<T> f;
    f = new Instance1(); // no problem
    f = new Instance2(); // unchecked warning
  }
}


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

CUSTOMER SUBMITTED WORKAROUND :
Use a SuppressWarnings tag, or a previous compiler.

Comments
EVALUATION Not reproducible in 7 - it has been probably solved by the fix for 6657499
28-07-2009