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

importPackage not working even with load "Mozilla compatibility script"

    Details

    • Subcomponent:
    • Introduced In Version:
      8
    • Resolved In Build:
      b34
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      Global variable not accessible when I load "Mozilla compatibility script" and call the "ScriptEngineManager.setBindings" method.

      "engine.eval("var sample = new SampleMain2();")" throws an ScriptException.
       If I comment out "other.eval("load(\"nashorn:...)" or "manager.setBindings(ot...)", the exception are not thrown.

      code:
      public class SampleMain {
          public static void main(String[] args) throws ScriptException {
              ScriptEngineManager manager = new ScriptEngineManager();
              ScriptEngine other = manager.getEngineByName("nashorn");
              other.eval("load(\"nashorn:mozilla_compat.js\");");
              manager.setBindings(other.getBindings(ScriptContext.ENGINE_SCOPE));

              ScriptEngine engine = manager.getEngineByName("nashorn");
              engine.eval("load(\"nashorn:mozilla_compat.js\");");
              engine.eval("importPackage(Packages.sample2);");
              engine.eval("var sample = new SampleMain2();");
          }
      }

      public class SampleMain2 { }

      exception:
      Exception in thread "main" javax.script.ScriptException: ReferenceError: "SampleMain2" is not defined in <eval> at line number 1
      at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:467)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:451)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:403)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:399)
      at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155)
      at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)

      REGRESSION. Last worked in version 7u80


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" javax.script.ScriptException: ReferenceError: "SampleMain2" is not defined in <eval> at line number 1
      at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:467)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:451)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:403)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:399)
      at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155)
      at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
      at jp.co.hoge.SampleMain.main(SampleMain.java:27)
      Caused by: <eval>:1 ReferenceError: "SampleMain2" is not defined
      at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)
      at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:319)
      at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:291)
      at jdk.nashorn.internal.objects.Global.__noSuchProperty__(Global.java:1432)
      at jdk.nashorn.internal.scripts.Script$7$\^eval\_.:program(<eval>:1)
      at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:640)
      at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228)
      at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:446)
      ... 5 more

      REPRODUCIBILITY :
      This bug can be reproduced always.

        Attachments

          Activity

            People

            • Assignee:
              sundar Sundararajan Athijegannathan
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: