JDK-8143642 : Nashorn shebang argument handling is broken
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 8u60,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-11-23
  • Updated: 2016-10-13
  • Resolved: 2015-11-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
8u112Fixed 9 b96Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Shebang arguments are not handled properly. A script like the following one will drop the user in the jjs REPL without being run:

#!/usr/local/bin/jjs -scripting -- hello
print(arguments)

$ ./shebang.js world
jjs>

It is possible to at least have the script executed by inserting the name of the script file in the shebang line, but the arguments are not ordered properly:

#!/usr/local/bin/jjs -scripting shebang.js -- hello
print(arguments)

$ ./shebang.js world
hello,./shebang.js,world
Comments
JDK-8144142: With JDK-8143642, shebang argument handling was fixed for Mac OS X. On that platform, shebang arguments are passed in to Nashorn as an array of arguments separated along spaces. Linux passes the shebang arguments in to Nashorn as one string. This string needs to be split into single arguments properly, in which process delimited strings (with single or double quotes) must be taken into account.
27-11-2015

The original fix broke testing on Windows 7 (JDK-8144160): with latest jdk9-dev tip build set as JAVA_HOME, nashorn's ant test fails to complete. [testng] Test(compile, run): test\script\trusted\event_queue.js [testng] jjs [<options>] <files> [-- <arguments>] [testng] "Illegal char <:> at index 15: --log=recompile:quiet" is not a recognized option. Use "-h" or "-help" to see a list of all supported options. [testng] [testng] [testng] Test(compile, run): test\script\trusted\getenv.js [testng] Test(compile, run): test\script\trusted\optimistic_recompilation.js [testng] jjs [<options>] <files> [-- <arguments>] [testng] "Illegal char <:> at index 15: --log=recompile:quiet" is not a recognized option. Use "-h" or "-help" to see a list of all supported options. [testng] [testng] [testng] Test(compile, run): test\script\trusted\urlreader.js [testng] [testng] =============================================== [testng] Ant suite [testng] Total tests run: 1558, Failures: 2, Skips: 0 [testng] =============================================== [testng] [testng] [TestNG] Time taken by org.testng.reporters.jq.Main@f6c48ac: 513 ms [testng] [TestNG] Time taken by [FailedReporter passed=1556 failed=2 skipped=0]: 146 ms [testng] [TestNG] Time taken by org.testng.reporters.EmailableReporter@271053e1: 874 ms [testng] [TestNG] Time taken by jdk.nashorn.internal.test.framework.JSJUnitReportReporter@6500df86: 307 ms [testng] [TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@5622fdf: 3489 ms [testng] [TestNG] Time taken by org.testng.reporters.XMLReporter@553f17c: 190 ms BUILD FAILED D:\src\jdk9-dev\nashorn\make\build.xml:552: The following error occurred while executing this line: D:\src\jdk9-dev\nashorn\make\build.xml:513: The tests failed. Total time: 4 minutes 27 seconds The regression is seen on Windows 7 after fix for JDK-8143642
27-11-2015

The original fix broke the case where a shebang expression has no arguments at all, and no arguments are passed: #!/usr/local/bin/jjs print(23) Running this script without passing any arguments will break with an IndexOutOfBoundsException. (JDK-8144149)
27-11-2015

Observed failures on other platforms.
27-11-2015