JDK-8326588 : Setting of nashorn.args has changed (and does not work)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 17.0.10
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2024-02-22
  • Updated: 2025-06-14
Description
A DESCRIPTION OF THE PROBLEM :
Customer reported (https://shibboleth.atlassian.net/browse/JSCRIPTING-19) that whereas in JDK11 the following worked and supressed deprecations warnings

-Dnashorn.args=--no-deprecation-warning)

In JDK17 with nashorn-core-15.4.1 (inserted onto the classpath) this doesn't work.  Instead the scripting engine SILENTLY fails to load.

Spelunking the code shows me that the property setting paradigm has changed to 

-Dnashorn.args=-D--no-deprecation-warning

or even 

-D--no-deprecation-warning

this appears to make the property available to the Nashorn scripting engine.  Customer additionally reports that even with this set the warnings are still emitted.

1) Why does the engine silently fail to load (rather than throw an exception or print a log message)?
2) Is this change documented (so I can reflect it in our documentation)
3) Why, even with that parameterization, does the engine still warn?
[2024-02-22 08:29:26] [info] Warning: Nashorn engine is planned to be removed from a future JDK release

REGRESSION : Last worked in version 11.0.22

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) add nashorn to you class path
2) Run this code segment

System.setProperty("nashorn.args","-no-deprecation-warning");
final ScriptEngineManager engineManager = new ScriptEngineManager();
final ScriptEngine scriptEngine = engineManager.getEngineByName("javascript");
assert scriptEngine != null;
nothing happens because the engine fails to load


---------- BEGIN SOURCE ----------
https://git.shibboleth.net/view/?p=java-idp-plugin-scripting.git;a=blob;f=nashorn-jdk-impl/src/test/java/net/shibboleth/idp/plugin/scripting/nashorn/EngineTests.java;h=abab340b30e211d7ec9e026a4f99704a781ba4a4;hb=HEAD

Has the test but with the problem fixed.
---------- END SOURCE ----------

FREQUENCY : always



Comments
1) The engine does throw an exception, but it is the JDK ScriptEngineManager that swallows the exception, see https://github.com/openjdk/jdk/blob/master/src/java.scripting/share/classes/javax/script/ScriptEngineManager.java#L236-L238. If you run the example with -Dnashorn.debug=true you will see an exception printed because then Nashorn prints it before ScriptEngineManager can discard it. 2) Nashorn interprets "-D" in argument list as a request to define a system property. So "-Dnashorn.args=-D--no-deprecation-warning" will be essentially equivalent to "-D--no-deprecation-warning" (a system property with key "--no-deprecation-warning" will be defined.) It will not enable the flag. We did not change the way Nashorn args are set. 2) However, we silently discarded the --no-deprecation-warning command line argument with Nashorn 15.0 and we don't recognize it anymore, see https://github.com/openjdk/nashorn/pull/3/files#diff-d9b3e8e424d5d8c23ef566ace1a10551e5d77fefc1148d8b160e4c72b32bdb20L226-L233.. That change is unfortunately not documented. Since the standalone version of Nashorn does not need to warn about the deprecation, it is no longer needed. For backwards compatibility we could've kept it as a no-op. 3) It is now hopefully clear that specifying flags with -Dnashorn.args=-D… is not correct, so maybe a built-in version of Nashorn warns because you didn't actually specify the flag. The standalone version of Nashorn does not ever warn.
14-06-2025

The scripting engine not working on JDK 17 due to NashornScriptEngineFactory itself is deprecated. we getting below error in jdk17 Exception in thread "main" java.lang.NullPointerException: Cannot invoke "javax.script.ScriptEngine.eval(String)" because "scriptEngine" is null (edited) however in jdk 11, giving below warming : Warning: Nashorn engine is planned to be removed from a future JDK release
22-02-2024