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

NashornScriptEngine returns javax.script.ScriptContext instance which doesn't completely conform to the spec regarding exceptions throwing

    XMLWordPrintable

    Details

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

      Description

      The spec
      http://docs.oracle.com/javase/8/docs/api/javax/script/ScriptContext.html
      asserts plenty of IAE/NPE exception throwing for getter/setter methods, however this is not completely fulfilled by the state/instance of SimpleScriptContext used by NashornScriptEngine; the following code will produce no exceptions:


              new ScriptEngineManager()
                  .getEngineFactories()
                  .stream()
                  .map(ScriptEngineFactory::getScriptEngine)
                  .map(engine -> {
                      System.err.println("engine: " + engine);
                      return engine.getContext();
                  })
                  .forEach(c -> {
                      System.err.println("context: " + c);
                      c.getAttribute("");
                      c.getAttribute(null);
                      c.getAttribute("", ScriptContext.ENGINE_SCOPE);
                      c.getAttribute(null, ScriptContext.ENGINE_SCOPE);
                      c.removeAttribute(null, ScriptContext.ENGINE_SCOPE);
                      c.removeAttribute("", ScriptContext.ENGINE_SCOPE);
                      c.setAttribute("", "value", ScriptContext.ENGINE_SCOPE);
                      c.setAttribute(null, "value", ScriptContext.ENGINE_SCOPE);
                      c.getAttributesScope("");
                      c.getAttributesScope(null);
                  });

      However if SimpleScriptContext instance is created manually the expected exceptions are thrown - any of the following lines WILL cause the expected NPE or IAE:

              new SimpleScriptContext().getAttribute("");
              new SimpleScriptContext().getAttribute(null);
              new SimpleScriptContext().getAttribute("", ScriptContext.ENGINE_SCOPE);
              new SimpleScriptContext().getAttribute(null, ScriptContext.ENGINE_SCOPE);
              new SimpleScriptContext().removeAttribute(null, ScriptContext.ENGINE_SCOPE);
              new SimpleScriptContext().removeAttribute("", ScriptContext.ENGINE_SCOPE);
              new SimpleScriptContext().setAttribute("", "value", ScriptContext.ENGINE_SCOPE);
              new SimpleScriptContext().setAttribute(null, "value", ScriptContext.ENGINE_SCOPE);
              new SimpleScriptContext().getAttributesScope("");
              new SimpleScriptContext().getAttributesScope(null);

      ---

      The following JCK9 tests will fail due to the problem with Nashorn:

      api/javax_script/ScriptContext/index.html#Exceptions[getAttribute_IAE_emptyName]
      api/javax_script/ScriptContext/index.html#Exceptions[getAttribute_NPE]
      api/javax_script/ScriptContext/index.html#Exceptions[getAttribute_noScope_IAE_emptyName]
      api/javax_script/ScriptContext/index.html#Exceptions[getAttribute_noScope_NPE]
      api/javax_script/ScriptContext/index.html#Exceptions[getAttributesScope_noScope_IAE_emptyName]
      api/javax_script/ScriptContext/index.html#Exceptions[getAttributesScope_noScope_NPE]
      api/javax_script/ScriptContext/index.html#Exceptions[removeAttribute_IAE_emptyName]
      api/javax_script/ScriptContext/index.html#Exceptions[removeAttribute_NPE]
      api/javax_script/ScriptContext/index.html#Exceptions[setAttribute_IAE_emptyName]
      api/javax_script/ScriptContext/index.html#Exceptions[setAttribute_NPE]

      Please note these tests are not targeted or specific for Nashorn - they check any implementation found on a particular JavaSE platform and they fail for Oracle JDK.



        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: