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

javac (generic) unable to resolve methods

    Details

    • Subcomponent:
    • Resolved In Build:
      b27
    • CPU:
      x86
    • OS:
      windows_xp
    • Verification:
      Not verified

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0_05"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      javac failes to resolve the generic invocation for the methods as detailed in the code segments

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      compile the code supplied

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      code should compile and run
      ACTUAL -
      erro produced from javac


      ERROR MESSAGES/STACK TRACES THAT OCCUR :

       <L,LF>addOrCreate4(java.lang.Number,L,LF) in NewTest<java.lang.Long,java.lang.Number> cannot be applied to (int,java.util.List<java.lang.Number>,NewTest.ListFactory<java.lang.Number>)


      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class NewTest<A,B> {
          private List<A> toAdd;
          
          public NewTest(List<A> toAdd) {
              this.toAdd = toAdd;
          }
          
          private List<A> getRelated(B b) {
              //some application logic
              //for demo
              return toAdd;
          }
          
          @SuppressWarnings("unchecked")
          public <L extends List<? super A>,LF extends Factory<L>> L addOrCreate4(B b,L l,LF lf) {
              if (l == null) {
                  l = lf.create();
              }
              ((List<? super A>)l).addAll(getRelated(b)); //to get round the compiler bug
              return l;
          }
          
          public static class ListFactory<T> implements Factory<List<T>>{
              public List<T> create() {
                  return new ArrayList<T>();
              }
          }
          public static interface Factory<T> {
              public T create();
          }
          
          public static void main(String ... args) {
              ListFactory<Number> lf = new ListFactory<Number>();
              List<Long> longs = new ArrayList<Long>();
              longs.add(new Long(1));
              NewTest<Long,Number> test = new NewTest<Long,Number>(longs);
              
              List<Number> ret4 = null;
              
              ret4 = test.addOrCreate4(1, ret4,lf);
              
          }
      }

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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mcimadamore Maurizio Cimadamore
                Reporter:
                rmandalasunw Ranjith Mandala (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: