Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8158467

AccessControlException is thrown on public Java class access if "script app loader" is set to null

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b122
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        File: Main.java

        import jdk.nashorn.api.scripting.*;
        import javax.script.*;

        public class Main {
          public static void main(String[] args) throws Exception {
             NashornScriptEngineFactory fac = new NashornScriptEngineFactory();
             // you null as ClassLoader for "app loader" for script engine.
             ScriptEngine e = fac.getScriptEngine((ClassLoader)null);
             // try to access public class from an exported package
             e.eval("java.lang.System");
          }
        }

        File: t.policy

        grant {
           permission java.lang.RuntimePermission "nashorn.setConfig";
        };

        Compile and run the above program using jdk9 with these commands:

        $ javac Main.java
        $ java -Djava.security.manager -Djava.security.policy=t.policy Main

        Exception in thread "main" java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getClassLoader")
        at java.security.AccessControlContext.checkPermission(java.base@9-internal/AccessControlContext.java:468)
        at java.security.AccessController.checkPermission(java.base@9-internal/AccessController.java:894)
        at java.lang.SecurityManager.checkPermission(java.base@9-internal/SecurityManager.java:541)
        at java.lang.Class.forName(java.base@9-internal/Class.java:373)
        at jdk.nashorn.internal.runtime.Context.findClass(jdk.scripting.nashorn@9-internal/Context.java:1169)
        at jdk.nashorn.internal.runtime.NativeJavaPackage.createProperty(jdk.scripting.nashorn@9-internal/NativeJavaPackage.java:236)
        at jdk.nashorn.internal.runtime.NativeJavaPackage.noSuchProperty(jdk.scripting.nashorn@9-internal/NativeJavaPackage.java:205)
        at jdk.nashorn.internal.runtime.ScriptObject.findGetMethod(jdk.scripting.nashorn@9-internal/ScriptObject.java:1987)
        at jdk.nashorn.internal.runtime.ScriptObject.lookup(jdk.scripting.nashorn@9-internal/ScriptObject.java:1853)
        at jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(jdk.scripting.nashorn@9-internal/NashornLinker.java:104)
        at jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(jdk.scripting.nashorn@9-internal/NashornLinker.java:96)
        at jdk.dynalink.linker.support.CompositeTypeBasedGuardingDynamicLinker.getGuardedInvocation(jdk.dynalink@9-internal/CompositeTypeBasedGuardingDynamicLinker.java:184)
        at jdk.dynalink.linker.support.CompositeGuardingDynamicLinker.getGuardedInvocation(jdk.dynalink@9-internal/CompositeGuardingDynamicLinker.java:132)
        at jdk.dynalink.LinkerServicesImpl.lambda$getGuardedInvocation$0(jdk.dynalink@9-internal/LinkerServicesImpl.java:160)
        at jdk.dynalink.LinkerServicesImpl.getWithLookupInternal(jdk.dynalink@9-internal/LinkerServicesImpl.java:191)
        at jdk.dynalink.LinkerServicesImpl.getGuardedInvocation(jdk.dynalink@9-internal/LinkerServicesImpl.java:158)
        at jdk.dynalink.DynamicLinker.relink(jdk.dynalink@9-internal/DynamicLinker.java:265)
        at jdk.nashorn.internal.scripts.Script$Recompilation$1$\^eval\_.:program(jdk.scripting.nashorn.scripts/<eval>:1)
        at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(jdk.scripting.nashorn@9-internal/ScriptFunctionData.java:654)
        at jdk.nashorn.internal.runtime.ScriptFunction.invoke(jdk.scripting.nashorn@9-internal/ScriptFunction.java:513)
        at jdk.nashorn.internal.runtime.ScriptRuntime.apply(jdk.scripting.nashorn@9-internal/ScriptRuntime.java:489)
        at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(jdk.scripting.nashorn@9-internal/NashornScriptEngine.java:445)
        at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(jdk.scripting.nashorn@9-internal/NashornScriptEngine.java:402)
        at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(jdk.scripting.nashorn@9-internal/NashornScriptEngine.java:398)
        at jdk.nashorn.api.scripting.NashornScriptEngine.eval(jdk.scripting.nashorn@9-internal/NashornScriptEngine.java:154)
        at javax.script.AbstractScriptEngine.eval(java.scripting@9-internal/AbstractScriptEngine.java:264)
        at Main.main(Main.java:8)

          Activity

          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/dev/nashorn/rev/65b4db247568
          User: sundar
          Date: 2016-06-02 09:26:41 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/nashorn/rev/65b4db247568 User: sundar Date: 2016-06-02 09:26:41 +0000
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/jdk9/nashorn/rev/65b4db247568
          User: lana
          Date: 2016-06-08 20:34:55 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/nashorn/rev/65b4db247568 User: lana Date: 2016-06-08 20:34:55 +0000

            People

            • Assignee:
              sundar Sundararajan Athijegannathan
              Reporter:
              sundar Sundararajan Athijegannathan
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: