Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6730468

javac infers inapplicable method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6
    • tools
    • x86
    • linux

      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?

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: