Invoking a default method can cause IllegalAccessError

Dan Smith daniel.smith at oracle.com
Mon Apr 1 16:09:42 PDT 2013


This is a known bug:
http://bugs.sun.com/view_bug.do?bug_id=8009130

It's actually the VM, not javac, that is generating the faulty invokespecial call...

—Dan

On Mar 31, 2013, at 7:36 AM, Stephan Herrmann <stephan.herrmann at berlin.de> wrote:

> 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