Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8143642

Nashorn shebang argument handling is broken

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8u60, 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:

      Backports

        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

          Issue Links

            Activity

            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/dev/nashorn/rev/d98fe27f6ba9
            User: mhaupt
            Date: 2015-11-26 11:00:06 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/nashorn/rev/d98fe27f6ba9 User: mhaupt Date: 2015-11-26 11:00:06 +0000
            Hide
            mhaupt Michael Haupt added a comment -
            Observed failures on other platforms.
            Show
            mhaupt Michael Haupt added a comment - Observed failures on other platforms.
            Hide
            mhaupt Michael Haupt added a comment -
            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)
            Show
            mhaupt Michael Haupt added a comment - 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 )
            Hide
            mhaupt Michael Haupt added a comment - - edited
            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
            Show
            mhaupt Michael Haupt added a comment - - edited 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
            Hide
            mhaupt Michael Haupt added a comment -
            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.
            Show
            mhaupt Michael Haupt added a comment - 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.
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/jdk9/nashorn/rev/d98fe27f6ba9
            User: lana
            Date: 2015-12-10 00:26:41 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/nashorn/rev/d98fe27f6ba9 User: lana Date: 2015-12-10 00:26:41 +0000

              People

              • Assignee:
                mhaupt Michael Haupt
                Reporter:
                mhaupt Michael Haupt
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: