JDK-8059938 : NPE restoring cached script with optimistic types disabled
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2014-10-08
  • Updated: 2015-06-04
  • Resolved: 2014-10-08
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
8u40Fixed 9 b35Fixed
Description
A NullPointerException occurs when installing scripts from persistent cache with optimistic types disabled. When running the script below twice:

$ java -jar dist/nashorn.jar --optimistic-types=false -pcc ./test/script/basic/JDK-8048079_2a.js
parsed and compiled ok prototype.js
$ java -jar dist/nashorn.jar --optimistic-types=false -pcc ./test/script/basic/JDK-8048079_2a.js
Exception in thread "main" java.lang.NullPointerException
	at jdk.nashorn.internal.runtime.Context.install(Context.java:1249)
	at jdk.nashorn.internal.runtime.Context.compile(Context.java:1192)
	at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:1123)
	at jdk.nashorn.internal.runtime.Context.evaluateSource(Context.java:1089)
	at jdk.nashorn.internal.runtime.Context.load(Context.java:773)
	at jdk.nashorn.internal.objects.Global.load(Global.java:1000)
	at jdk.nashorn.internal.scripts.Script$JDK_8048079_2a.:program(./test/script/basic/JDK-8048079_2a.js:34)
	at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:636)
	at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:229)
	at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:387)
	at jdk.nashorn.tools.Shell.apply(Shell.java:394)
	at jdk.nashorn.tools.Shell.runScripts(Shell.java:323)
	at jdk.nashorn.tools.Shell.run(Shell.java:169)
	at jdk.nashorn.tools.Shell.main(Shell.java:133)
	at jdk.nashorn.tools.Shell.main(Shell.java:112)

Obviously a function in the constants array may not have an initializer when lazy compilation is enabled, so we need to add a null check right there.

Comments
Adding noreg-sqe label. The fix will be verified by existing tests for JDK-8048079 after JDK-8059811 which makes sure these tests are run with optimistic types on and off.
09-10-2014