Invoking a default method can cause IllegalAccessError

Stephan Herrmann stephan.herrmann at berlin.de
Sun Mar 31 06:36:58 PDT 2013


Compile these 2 files using
	1.8.0-ea-lambda-nightly-h3673-20130312-b81-b00:

----8<--- p2/J.java ---8<----

package p2;
interface I {
     public default void foo() {
         System.out.println("default");
     }
}
public interface J extends I {}

----8<--- p1/C.java ---8<----

package p1;
public class C implements p2.J {
     public static void main(String[] args) {
         C c = new C();
         c.foo();
     }
}

----8<-----

Running p1.C yields:

Exception in thread "main" java.lang.IllegalAccessError: tried to access 
class p2.I from class p1.C
         at p1.C.foo(C.java)
         at p1.C.main(C.java:5)

Obviously javac forgot to generate a synthetic super access
into J (not expecting that interfaces ever need such, but ..)

cheers,
Stephan


More information about the lambda-dev mailing list