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

JSR292: lookup failure of a default method inherited from a parent

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 8
    • core-libs

      Lookup of a default method inherited from a parent interface fails.

      Pseudo-code:
        interface I { int m() default { return 1; } }
        interface J extends I {}
        interface K extends I {}
        class C implements J, K {}

      J o = new C(); o.m();

      Result:
        expected: o.m() == 1;
        actual: o.m() throws chain of (AME => IAE => ICCE) exceptions

      Fails with: MH.invokeExact, MH.invoke, MH.invokeWithArguments, invokedynamic.

      The test passes when invocation is done using invokeinterface on bytecode level.

      Invocation (for MH.invokeExact case):
               0: ldc #16 // MethodHandle invokeinterface J.m:()I
               2: new #18 // class C
               5: dup
               6: invokespecial #19 // Method C."<init>":()V
               9: astore_1
              10: aload_1
              11: invokevirtual #25 // Method java/lang/invoke/MethodHandle.invokeExact:(LJ;)I

      Failure:
      Exception in thread "main" java.lang.IncompatibleClassChangeError
      at java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(MethodHandleNatives.java:383)
      at Test2_J_C_m.test(Unknown Source)
      at Test.main(Test.java:3)
      Caused by: java.lang.IllegalAccessException: no such method: J.m()int/invokeInterface
      at java.lang.invoke.MemberName.makeAccessException(MemberName.java:761)
      at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:882)
      at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:1037)
      at java.lang.invoke.MethodHandles$Lookup.linkMethodHandleConstant(MethodHandles.java:1342)
      at java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(MethodHandleNatives.java:381)
      ... 2 more
      Caused by: java.lang.AbstractMethodError: J.m()I
      at java.lang.invoke.MethodHandleNatives.resolve(Native Method)
      at java.lang.invoke.MemberName$Factory.resolve(MemberName.java:854)
      at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:879)
      ... 5 more

      Test case is attached.

      How to run:
        $ java Test

            jrose John Rose
            vlivanov Vladimir Ivanov
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: