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

generic method return type inference regression

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 7u72, 8u25
    • tools
    • x86_64
    • linux

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      The following works in Eclipse and javac 1.8.0_11.
      javac 1.8.0_20 and 1.8.0_25 are broken:

      import java.util.LinkedList;

      public class Test
      {
      public static void main(String[] args)
      {
      LinkedList<Animal> l = new LinkedList<Animal>();
      l.add(l.getFirst().copy());
      }

      static class Animal
      {
      <T> T copy()
      {
      return null;
      }
      }
      }

      REGRESSION. Last worked in version 8u11

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      javac compiles the class
      ACTUAL -
      Test.java:8: error: no suitable method found for add(Object)
                      l.add(l.getFirst().copy());
                       ^
          method Collection.add(Animal) is not applicable
            (argument mismatch; Object cannot be converted to Animal)
          method List.add(Animal) is not applicable
            (argument mismatch; Object cannot be converted to Animal)
          method AbstractCollection.add(Animal) is not applicable
            (argument mismatch; Object cannot be converted to Animal)
          method AbstractList.add(Animal) is not applicable
            (argument mismatch; Object cannot be converted to Animal)
          method LinkedList.add(Animal) is not applicable
            (argument mismatch; Object cannot be converted to Animal)
      Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
      1 error

      REPRODUCIBILITY :
      This bug can be reproduced always.

            jlahoda Jan Lahoda
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: