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

Ambiguous method call with generics may cause FunctionDescriptorLookupError

XMLWordPrintable

    • b01
    • 11
    • b11
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      FunctionDescriptorLookupError occurs when compiling sample code that should result in a compile error.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Invoke javac with sample code.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Test.java:9: error: reference to test is ambiguous
          test(list.get(0));
          ^
        both method test(A<?>) in Test and method test(B<?>) in Test match

      ACTUAL -
      An exception has occurred in the compiler (22.0.1). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
      com.sun.tools.javac.code.Types$FunctionDescriptorLookupError


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

      public class Test {
        public static void main(String[] args) {
          List<X> list = List.of(new X());

          // var x = list.get(0);
          // test(x);
          test(list.get(0));
        }

        static void test(A<?> a) { }
        static void test(B<?> b) { }

        interface A<T extends A<T>> { T a(); }
        interface B<T extends B<T>> /* extends A<T> */ { T b(); }
        static class X implements A<X>, B<X> {
          public X a() { return null; }
          public X b() { return null; }
        }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      (1) split calling code (line 9 to line 7&8)
      (2) resolve ambiguous code


      FREQUENCY : always


            vromero Vicente Arturo Romero Zaldivar
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: