JDK-8191196 : NullPointerException at jdk.nashorn.internal.runtime.Context.getContext(Context.java:1393)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 9.0.1
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86_64
  • Submitted: 2017-11-11
  • Updated: 2017-11-17
  • Resolved: 2017-11-17
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 10
10Resolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
openjdk version "9.0.1"
OpenJDK Runtime Environment (build 9.0.1+11)
OpenJDK 64-Bit Server VM (build 9.0.1+11, mixed mode)

A DESCRIPTION OF THE PROBLEM :
Running the test case with Java 9 results in a NullPointerException. It runs successfully with Java 8.

REGRESSION.  Last worked in version 8u151

ADDITIONAL REGRESSION INFORMATION: 
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Standard output contains:
Executed
ACTUAL -
Standard output contains:
Exception in thread "main" java.lang.BootstrapMethodError: call site initialization exception
	at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:385)
	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:250)
	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:240)
	at jdk.nashorn.javaadapters.com_example_nashorn_npe_JdkScriptingNashornNPE$CustomMenu.isManagingFocus(Unknown Source)
	at java.desktop/javax.swing.JComponent.<init>(JComponent.java:603)
	at java.desktop/javax.swing.AbstractButton.<init>(AbstractButton.java:74)
	at java.desktop/javax.swing.JMenuItem.<init>(JMenuItem.java:145)
	at java.desktop/javax.swing.JMenuItem.<init>(JMenuItem.java:124)
	at com.example.nashorn.npe.JdkScriptingNashornNPE$CustomMenu.<init>(JdkScriptingNashornNPE.java:20)
	at jdk.nashorn.javaadapters.com_example_nashorn_npe_JdkScriptingNashornNPE$CustomMenu.<init>(Unknown Source)
	at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$2$\^eval\_$cu1$restOf/758348212.:program(<eval>:1)
	at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:652)
	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:517)
	at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:448)
	at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:405)
	at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:401)
	at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:154)
	at java.scripting/javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
	at com.example.nashorn.npe.JdkScriptingNashornNPE.main(JdkScriptingNashornNPE.java:12)
Caused by: java.lang.NullPointerException
	at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.Context.getContext(Context.java:1393)
	at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.Context.getContextTrusted(Context.java:1303)
	at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.Context.fromClass(Context.java:1419)
	at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.Context.getDynamicLinker(Context.java:1315)
	at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.linker.Bootstrap.bootstrap(Bootstrap.java:223)
	at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.linker.JavaAdapterServices.bootstrap(JavaAdapterServices.java:206)
	at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:324)
	... 19 more

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package com.example.nashorn.npe;

import javax.script.ScriptEngineManager;
import javax.swing.JMenuItem;

public class JdkScriptingNashornNPE {

    private static final String SCRIPT = "var CustomMenu = Java.type('com.example.nashorn.npe.JdkScriptingNashornNPE$CustomMenu');"
            + "new CustomMenu('') { custom: function() { print('Executed.') } }.custom()";

    public static void main(String[] args) throws Exception {
        new ScriptEngineManager().getEngineByName("ECMAScript").eval(SCRIPT);
    }

    public abstract static class CustomMenu extends JMenuItem {

        private static final long serialVersionUID = 1L;

        public CustomMenu(String label) {
            super(label);
        }

        public abstract void custom();
    }
}
---------- END SOURCE ----------


Comments
Duplicate of JDK-8184241
17-11-2017

To reproduce the issue, run the attached test case. JDK 8u151 - Pass JDK 9-ea+102- Pass JDK9-ea+103 - Fail JDK 9 + 181 - Fail JDK 9.0.1 - Fail JDK 10-ea+30- Pass Output on failed versions : Exception in thread "main" java.lang.BootstrapMethodError: call site initialization exception at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:385) at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:250) at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:240) at jdk.nashorn.javaadapters.com_example_nashorn_npe_JdkScriptingNashornNPE$CustomMenu.isManagingFocus(Unknown Source) at java.desktop/javax.swing.JComponent.<init>(JComponent.java:603) at java.desktop/javax.swing.AbstractButton.<init>(AbstractButton.java:74) at java.desktop/javax.swing.JMenuItem.<init>(JMenuItem.java:145) at java.desktop/javax.swing.JMenuItem.<init>(JMenuItem.java:124) at com.example.nashorn.npe.JdkScriptingNashornNPE$CustomMenu.<init>(JdkScriptingNashornNPE.java:18) at jdk.nashorn.javaadapters.com_example_nashorn_npe_JdkScriptingNashornNPE$CustomMenu.<init>(Unknown Source) at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$2$\^eval\_$cu1$restOf/757004314.:program(<eval>:1) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:652) 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:517) at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:448) at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:405) at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:401) at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:154) at java.scripting/javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) at com.example.nashorn.npe.JdkScriptingNashornNPE.main(JdkScriptingNashornNPE.java:10) Caused by: java.lang.NullPointerException at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.Context.getContext(Context.java:1393) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.Context.getContextTrusted(Context.java:1303) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.Context.fromClass(Context.java:1419) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.Context.getDynamicLinker(Context.java:1315) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.linker.Bootstrap.bootstrap(Bootstrap.java:223) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.linker.JavaAdapterServices.bootstrap(JavaAdapterServices.java:206) at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:324) ... 19 more
14-11-2017