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

ScriptEngine throws exception when evaluating importClass and importPackage

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Not an Issue
    • Affects Version/s: 8
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0-ea"
      Java(TM) SE Runtime Environment (build 1.8.0-ea-b106)
      Java HotSpot(TM) 64-Bit Server VM (build 25.0-b48, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      New scripting engine introduced in Java 8 no longer seems to handle importClass or importPackage built-in functions. When referenced in a scripting, it throws javax.script.ScriptException: ReferenceError: "importClass" is not defined in <eval> at line number ...

      REGRESSION. Last worked in version 7u21

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the source code specified in this bug report


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      SEVERE: null
      javax.script.ScriptException: ReferenceError: "importClass" is not defined in <eval> at line number 1
      at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:553)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:537)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:517)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:513)
      at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:202)
      at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
      at java8scripting.Java8Scripting.main(Java8Scripting.java:15)
      Caused by: <eval>:1 ReferenceError: "importClass" 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.api.scripting.NashornScriptEngine.__noSuchProperty__(NashornScriptEngine.java:286)
      at jdk.nashorn.internal.scripts.Script$engine._L35(nashorn:engine/resources/engine.js:37)
      at jdk.nashorn.internal.scripts.Script$\^eval\_.runScript(<eval>:1)
      at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:527)
      at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:204)
      at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:395)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:535)
      ... 5 more

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package java8scripting;

      import java.util.logging.Level;
      import java.util.logging.Logger;
      import javax.script.ScriptEngine;
      import javax.script.ScriptEngineManager;

      public class Java8Scripting {
          public static void main(String[] args)
          {
              try
              {
                  ScriptEngineManager factory = new ScriptEngineManager();
                  ScriptEngine engine = factory.getEngineByName("JavaScript") ;
                  engine.eval("importClass(java.util.Vector)
      " +
                          "print(\"Hello world\") ;");
              }
              catch (Exception ex)
              {
                  Logger.getLogger(Java8Scripting.class.getName()).log(Level.SEVERE, null, ex);
              }
          }
      }

      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              ndcosta Nelson Dcosta
              Reporter:
              ndcosta Nelson Dcosta
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: