JDK-7042829 : JSR292: MethodHandles$Lookup.findStatic[S|G]etter throws InternalError if SecurityManager is set
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2011-05-08
  • Updated: 2012-03-22
  • Resolved: 2011-05-14
Related Reports
Duplicate :  
Relates :  
Description
Minimized test:
===============
$ cat test.java
import java.lang.invoke.*;

public class test {
    public static void main(String[] args) throws Throwable {
        System.setSecurityManager(new SM());

        MethodHandle mh = MethodHandles.lookup().findStaticSetter(
                GetSet.class, "sf1", int.class);
    }
}

class SM extends SecurityManager {
    protected SM() { super(); }
}

class GetSet {
    static int sf1;
}

Minimized test output:
======================
$ javac test.java

$ java -showversion test
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b140)
Java HotSpot(TM) Server VM (build 21.0-b10, mixed mode)

Exception in thread "main" java.lang.InternalError: uncaught exception
        at java.lang.invoke.MethodHandleStatics.uncaughtException(MethodHandleStatics.java:84)
        at java.lang.invoke.MethodHandleImpl$FieldAccessor.staticBase(MethodHandleImpl.java:314)
        at java.lang.invoke.MethodHandleImpl$FieldAccessor.<init>(MethodHandleImpl.java:278)
        at java.lang.invoke.MethodHandleImpl.accessField(MethodHandleImpl.java:241)
        at java.lang.invoke.MethodHandles$Lookup.makeAccessor(MethodHandles.java:1103)
        at java.lang.invoke.MethodHandles$Lookup.makeAccessor(MethodHandles.java:1094)
        at java.lang.invoke.MethodHandles$Lookup.findStaticSetter(MethodHandles.java:785)
        at test.main(test.java:7)
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessDeclaredMembers")
        at java.security.AccessControlContext.checkPermission(AccessControlContext.java:366)
        at java.security.AccessController.checkPermission(AccessController.java:555)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
        at java.lang.SecurityManager.checkMemberAccess(SecurityManager.java:1679)
        at java.lang.Class.checkMemberAccess(Class.java:2174)
        at java.lang.Class.getDeclaredField(Class.java:1896)
        at java.lang.invoke.MethodHandleImpl$FieldAccessor.staticBase(MethodHandleImpl.java:311)
        ... 6 more

Comments
EVALUATION FieldAccessor.staticBase is masking exceptions in InternalError. It needs to pass through the exception which the security manager is trying to throw.
13-05-2011