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

Nashorn crashes when given an empty script file.

XMLWordPrintable

    • b36
    • x86_64
    • windows

        FULL PRODUCT VERSION :
        java version "9.0.1"
        Java(TM) SE Runtime Environment (build 9.0.1+11)
        Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 10.0.16299.98]

        A DESCRIPTION OF THE PROBLEM :
        Nashorn crashes with NullPointerException when passed an empty script file:

        jjs empty.js

        Fails only when file is totally empty, size=0. If file contains a single space character, or a single '0' character, does not crash.

        REGRESSION. Last worked in version 7u79

        ADDITIONAL REGRESSION INFORMATION:
        I know the empty file did work OK in a *fairly* recent prior version, but not certain which one. Just tried using java 8 and it failed the same way. Just guessing about java 7.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run:

        jjs empty.js

        where empty.js is a zero-length file.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Should to nothing, and not crash An empty string is a valid JavaScript program.
        ACTUAL -
        Crashes.

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        >jjs empty.js
        Exception in thread "main" java.lang.NullPointerException
                at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.preprocessArgs(Shell.java:298)
                at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.makeContext(Shell.java:213)
                at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.run(Shell.java:166)
                at jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.main(Main.java:104)
                at jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.main(Main.java:80)

        REPRODUCIBILITY :
        This bug can be reproduced always.

        CUSTOMER SUBMITTED WORKAROUND :
        I use this command to get the Nashorn version from another program:

            jjs -v empty.js

        This is the only way I know to get the version. If the "empty.js" argument is omitted, interactive mode is entered.

        This used to work with an empty file, but now crashes. Workaround is to put a space in empty.js.

              pmuthuswamy Priya Lakshmi Muthuswamy (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: