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