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

nashorn throws NullPointerException when run String.prototype.endsWith(null)

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      According to ECMA-262 6th edition, nashorn should return 'false' if the argument of 'String.prototype.endsWith' is 'null' , but nashorn throws NullPointerException.
      #Testcase:
      var foo = function (s, suffix) {
      var p=s.endsWith(suffix);
      print(p);
      };
      var Parameter0 = "hello nashorn";
      var Parameter1 = null;
      foo(Parameter0, Parameter1);

      #Command:
      ./jdk-12.0.1/bin/jjs --language=es6 testcase.js

      #Output:
      Warning: The jjs tool is planned to be removed from a future JDK release
      Exception in thread "main" java.lang.NullPointerException
              at java.base/java.lang.String.endsWith(String.java:1494)
              at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$1$28060/0x0000000801268440.:program(../test/28060.js:1)
              at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:655)
              at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513)
              at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:527)
              at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.apply(Shell.java:522)
              at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.runScripts(Shell.java:451)
              at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.run(Shell.java:189)
              at jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.main(Main.java:100)
              at jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.main(Main.java:76)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      false

            hannesw Hannes Wallnoefer
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: