JDK-8081156 : jjs "nashorn.args" system property is not effective when script arguments are passed
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 8u45
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux_ubuntu
  • CPU: generic
  • Submitted: 2015-05-26
  • Updated: 2015-09-29
  • Resolved: 2015-05-27
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 b67Fixed
Description
Consider the following script:

#!/usr/bin/jjs -J-Dnashorn.args=-strict -scripting -fv
print('Hello');

When executed without arguments, prints Nashorn full version string.
When executed with arguments, does not print version string.

$> ./temp.js 
nashorn full version 1.8.0_45-b14
Hello
$> ./temp.js -- 
Hello
$> ./tem.js -- foobar
Hello

Parameters are being ignored (-strict, -ot, -doe, etc...) when arguments are passed.
Comments
Problem is that Options.process method stops at first "--" and treats everything after that as script arguments. But then "nashorn.args" is processed after processing user supplied args! This implies that if there are user supplied script arguments, nashorn.args System property is not processed at all! (as System property) So fix is to avoid adding all arguments to the same list (nashorn.args.prepend, nashorn.args and user supplied arguments) - instead each has to be processed separately.
27-05-2015

Even without using shebang executable, the same problem can be reproduced. For example, no error for the following => -strict mode is not effective jjs -J-Dnashorn.args=-strict -- arg1 arg2 jjs> eval = 23; Whereas we get error when using this: jjs -J-Dnashorn.args=-strict jjs> eval = 23;
27-05-2015