Relates :
|
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 instance of SimpleScriptContext used by NashornScriptEngine The problem shows up with GLOBAL_SCOPE. Please try the sample which represents the JCK conformance test which operates with all the available script engine on an abstract level - without any assumption that the Nashorn engine is present or not on the certified system. The following code throws no exceptions with JDK9b48: import javax.script.*; public class Test { public static void main(String[] args) { for (ScriptEngineFactory f : new ScriptEngineManager().getEngineFactories()) { ScriptEngine e = f.getScriptEngine(); ScriptContext c = e.getContext(); System.err.println("context: " + c); System.err.println("engine: " + e); c.getAttribute("", ScriptContext.GLOBAL_SCOPE); c.getAttribute(null, ScriptContext.GLOBAL_SCOPE); c.removeAttribute(null, ScriptContext.GLOBAL_SCOPE); c.removeAttribute("", ScriptContext.GLOBAL_SCOPE); c.setAttribute("", "value", ScriptContext.GLOBAL_SCOPE); c.setAttribute(null, "value", ScriptContext.GLOBAL_SCOPE); } } } The output would be like context: javax.script.SimpleScriptContext@19afc07 engine: jdk.nashorn.api.scripting.NashornScriptEngine@2db087 The problem (no exceptions thrown) is perfectly reproducible with just SimpleScriptContext instance: new SimpleScriptContext().getAttribute("", ScriptContext.GLOBAL_SCOPE); new SimpleScriptContext().getAttribute(null, ScriptContext.GLOBAL_SCOPE); new SimpleScriptContext().removeAttribute(null, ScriptContext.GLOBAL_SCOPE); new SimpleScriptContext().removeAttribute("", ScriptContext.GLOBAL_SCOPE); new SimpleScriptContext().setAttribute("", "value", ScriptContext.GLOBAL_SCOPE); new SimpleScriptContext().setAttribute(null, "value", ScriptContext.GLOBAL_SCOPE); The list of failing JCK9 tests: 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[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] api/javax_script/SimpleScriptContext/index.html#Exceptions[getAttribute_IAE_emptyName] api/javax_script/SimpleScriptContext/index.html#Exceptions[getAttribute_NPE] api/javax_script/SimpleScriptContext/index.html#Exceptions[removeAttribute_IAE_emptyName] api/javax_script/SimpleScriptContext/index.html#Exceptions[removeAttribute_NPE] api/javax_script/SimpleScriptContext/index.html#Exceptions[setAttribute_IAE_emptyName] api/javax_script/SimpleScriptContext/index.html#Exceptions[setAttribute_NPE]