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

compiler should infer method but I get: ambiguous methods error

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Not an Issue
    • Affects Version/s: 8u25
    • Fix Version/s: None
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_25"
      Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Window 7 64 bit

      A DESCRIPTION OF THE PROBLEM :
      When I try to compile attached piece of code I get error that call of method is ambiguous, but this is not true. Proper method should be inferred with ease. In java 1.7 this compiles without any error.

      Test case is in attached code, and I have also repo on github with this bug:

      https://github.com/wjtk/java8-inference-bug



      REGRESSION. Last worked in version 7u71

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.7.0_71"
      Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package pl.wkr.j8.inferencebug;

      import org.junit.Test;

      import java.util.Iterator;

      import static pl.wkr.j8.inferencebug.A.*;
      import static pl.wkr.j8.inferencebug.B.*;

      class A {
          public static <T> void methodA(Iterable<T> actual) {}
          public static <T> void methodA(Iterator<T> actual) {}
          public static void methodA(Throwable actual) {}
      }

      class B {
          public static <E extends Throwable> E methodB() {
              return null;
          }
      }


      public class InferenceBugTest {

          @Test
          public void should_infer_method() {
              methodA(methodB());
              /* ^^^
              Java 1.7 compiles this, but in 1.8(1.8.0_25) I get error:

                error: reference to methodA is ambiguous
                      methodA(methodB());
                      ^
                both method <T#1>methodA(Iterator<T#1>) in A and method <T#2>methodA(Iterable<T#2>) in A match
                where T#1,T#2 are type-variables:
                  T#1 extends Object declared in method <T#1>methodA(Iterator<T#1>)
                  T#2 extends Object declared in method <T#2>methodA(Iterable<T#2>)

                -------------
                 (change 'sourceCompatibility' in build.gradle to see behavior in java 1.7 and 1.8)
               */
          }
      }




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

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: