invokespecial of default methods in unrelated interfaces

Daniel Heidinga Daniel_Heidinga at
Thu Jun 13 10:31:55 PDT 2013

We've put together a defender method test case using invokespecial and we'd
like some confirmation of our spec interpretation.  The testcase is:

	interface A {
		default void m(){ System.out.println("A"); };
	interface B {
		default void m(){ System.out.println("B"); };
	interface C {
		default void m(){ System.out.println("C"); };
	class D implements A, B {
		void m() {
			C.super.m();  // Note, D does not implement C
		public static void main(String[] args) {
			new D().m();

While javac won't compile this, it is legal bytecode (generated with ASM
because class D is unrelated to interface C).  Executing 'new D().m()'
unfortunately crashes Hotspot b93.

The lambda changes to the JVM spec for invokespecial indicate 'The named
method is resolved ('. states "Method resolution attempts
to look up the referenced method in C and its superclasses".  As C clearly
has an implementation of m(), resolution should succeed and C.m() should be
called.  (As an aside, there is an issue with invokespecial referencing for interface sends: "If C is an interface, method resolution
throws an IncompatibleClassChangeError.")

Does anyone disagree with this interpretation of the spec?

-------------- next part --------------
An HTML attachment was scrubbed...

More information about the lambda-spec-experts mailing list