JDK-6730468 : javac infers inapplicable method
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2008-07-28
  • Updated: 2011-02-16
  • Resolved: 2008-07-28
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
1.6.0-b105

A DESCRIPTION OF THE PROBLEM :
Erroneous program compiles without error, but fails with a class cast exception at runtime.  There is no cast in the code.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile and run the enclosed code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should fail to compile.
ACTUAL -
compiles and runs, causing runtime error.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
        at G.main(G.java:14)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.*;

public class G {
  public static <U> U fill(U u, List<List<U>> list) {
    list.get(0).set(0, u);
    return u;
  }

  public static void main(String[] args) {
    List<String> l1 =  new ArrayList<String>();
    l1.add("foo");
    List<List<String>> strs = Collections.singletonList(l1);
    fill(1, strs);
    String s = l1.get(0);
  }
}
// thanks to Michael Nascimento for this example
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
get a better compiler?

Comments
EVALUATION This is the same issue observed in CR 6707034. Moreover, the fix for 6638712 also fix this one.
28-07-2008