execution fails with IncompatibleClassChangeError

Brian Goetz brian.goetz at oracle.com
Tue Dec 18 07:51:52 PST 2012


Yes, this is a known bug with constructor refs to private nested 
classes.  We are currently trying to figure out whether the solution 
needs to come from the compiler or the VM.  (In the meantime, you can 
make the Bar constructor but not class public, which should get you past 
your current problem without opening additional security holes.)

On 12/18/2012 6:38 AM, Anna Kozlova wrote:
> Hello,
>
>
>
> Running the following class
>
> {code}
>
> public class FooBar {
>
>      private static final class Bar {
>
>          private Bar() {
>
>          }
>
>      }
>
>
>
>      private interface I {
>
>          Bar create();
>
>      }
>
>
>
>      static void foo(I intf) {}
>
>
>
>      public static void main(String[] args) throws Exception {
>
>          foo(Bar::new);
>
>      }
>
> }
>
> {code}
>
>
>
> fails with
>
> Exception in thread "main" java.lang.IncompatibleClassChangeError
>
>                  at
> java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(MethodHandleNa
> tives.java:383)
>
>                  at p.FooBar.main(FooBar.java:18)
>
>                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)
>
>                  at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57
> )
>
>                  at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
> .java:43)
>
>                  at java.lang.reflect.Method.invoke(Method.java:474)
>
>                  at
> com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
>
> Caused by: java.lang.IllegalAccessException: member is private:
> p.FooBar$Bar.<init>()void/invokeSpecial, from p.FooBar
>
>                  at
> java.lang.invoke.MemberName.makeAccessException(MemberName.java:732)
>
>                  at
> java.lang.invoke.MethodHandles$Lookup.checkAccess(MethodHandles.java:1135)
>
>                  at
> java.lang.invoke.MethodHandles$Lookup.getDirectConstructor(MethodHandles.jav
> a:1243)
>
>                  at
> java.lang.invoke.MethodHandles$Lookup.linkMethodHandleConstant(MethodHandles
> .java:1270)
>
>                  at
> java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(MethodHandleNa
> tives.java:381)
>
>                  ... 6 more
>
>
>
> If I convert method reference to lambda expression or anonymous class
> everything works correctly.  Checked with b68.
>
>
>
> Thank you
> Anna
>
>
>
>


More information about the lambda-dev mailing list