JDK-8009129 : Illegal access error when calling method reference
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8,8-repo-lambda
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2013-02-27
  • Updated: 2019-09-11
  • Resolved: 2013-03-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b82Fixed
Related Reports
Blocks :  
Description
This started to fail when BaseStream was made package private:

import java.util.Arrays;
import java.util.stream.Stream;

public class IllegalAccessErrorTest {

     public static void main(String[] args) {

         Stream stream = Arrays.asList("a", "b").stream();
         System.err.println("iterator = " + stream.iterator());
         Iterable iterable = stream::iterator;
         System.err.println("iterable = " + iterable);
     }
}

when compiled/run on b73 the output is:


iterator = java.util.stream.ReferencePipeline$6@3256a5
Exception in thread "main" java.lang.IllegalAccessError: tried to access 
class java.util.stream.BaseStream from class IllegalAccessErrorTest
     at IllegalAccessErrorTest.main(IllegalAccessErrorTest.java:10)

Comments
verified in jdk8 b92.
06-06-2013

The problem is caused by javac emitting wrong descriptor in lambda metafactory call. The referenced method should be visible. However, if compiler is fixed, the following starts to fail (presumably because of 7087658): interface A { void m(); } interface B extends A { } class Test { public static void main(String[] args) { B b = ()->{}; b.m(); } } Output: Exception in thread "main" java.lang.IncompatibleClassChangeError at java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(MethodHandleNatives.java:383) at Test.main(intf05702.java:60) Caused by: java.lang.IllegalAccessException: no such method: B.m()void/invokeInterface at java.lang.invoke.MemberName.makeAccessException(MemberName.java:749) at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:870) at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:1032) at java.lang.invoke.MethodHandles$Lookup.linkMethodHandleConstant(MethodHandles.java:1264) at java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(MethodHandleNatives.java:381) ... 1 more Caused by: java.lang.AbstractMethodError: B.m()V at java.lang.invoke.MethodHandleNatives.resolve(Native Method) at java.lang.invoke.MemberName$Factory.resolve(MemberName.java:842) at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:867) ... 4 more
27-02-2013