JDK-8071989 : NashornScriptEngine returns javax.script.ScriptContext instance with insonsistent get/remove methods behavior for undefined attributes
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-01-30
  • Updated: 2015-09-29
  • Resolved: 2015-02-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u60Fixed 9 b51Fixed
Description
Consider the following methods:
http://docs.oracle.com/javase/8/docs/api/javax/script/ScriptContext.html#getAttribute-java.lang.String-int-
http://docs.oracle.com/javase/8/docs/api/javax/script/ScriptContext.html#removeAttribute-java.lang.String-int-

For attribute names which are undefined they behave differently for Nashorn:

        new ScriptEngineManager()
            .getEngineFactories()
            .stream()
            .map(ScriptEngineFactory::getScriptEngine)
            .map((engine) -> {
                System.err.println("engine = " + engine);
                return engine.getContext();
            })
            .forEach(c -> {
                System.err.println("context = " + c);
                System.err.println("get returns = " + c.getAttribute("undefinedname", ScriptContext.ENGINE_SCOPE));
                System.err.println("remove returns = " + c.removeAttribute("undefinedname", ScriptContext.ENGINE_SCOPE));
            });


When run v.s. OracleJDK the output will be like:


engine = jdk.nashorn.api.scripting.NashornScriptEngine@f3eef9
context = javax.script.SimpleScriptContext@3c4f91
get returns = null
remove returns = undefined


The following JCK9 test fails due to this:

api/javax_script/ScriptContext/index.html#SetGetAttribute[remove_noValueDefined]