JDK-8269731 : ExceptionInInitializerError trying to use nashorn 15.1.1 or 15.2 with Java 17+27
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 17,18
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2021-06-28
  • Updated: 2021-12-07
  • Resolved: 2021-12-07
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 18
18Resolved
Related Reports
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
Multiple OS (at least Windows 10 and Linux)

A DESCRIPTION OF THE PROBLEM :
When using ANT to build an xml file with embedded JavaScript using the openjdk version of Nashorn (nashorn-core:15.2.jar), we get an java.lang.ExceptionInInitializerError from org.openjdk.nashorn and the build fails.  We have tried using multiple versions of ANT (1.8.4, 1.9.6, 1.10.10), 2 different versions of ASM (9.1 and 9.2) the two latest versions of Java 17 (build 27 and build 28) all with the same result.

REGRESSION : Last worked in version 16.0.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Prep:  Download and set up the latest Apache ANT (1.10.10), OpenJDK Nashorn (15.2), ASM JAR files (9.2) (which are required by OpenJDK) and Java 17 (build 28)

Create the following file NashornTest.xml (with the required Nashorn and asm jar files in the corresponding locations and update as needed for various OS):

<project name="NashornTest">
   <target name="step1">
      <script language="javascript">
         <classpath>
            <pathelement path="C:\nashorn\nashorn-core-15.2.jar;C:\asm\asm-9.1.jar;C:\asm\asm-commons-9.1.jar;C:\asm\asm-tree-9.1.jar;C:\asm\asm-util-9.1.jar"/>
      	</classpath>
      </script>
   </target>
</project>

Then, using a recent version of ANT, like 1.10.10 and the most recent version of Nashorn 15.2, run the command:
ant -f NashornTest.xml step1

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Something similar to previous versions of Java.  Here is the result when running on Java 16.0.1:

step1:

BUILD SUCCESSFUL
Total time: 1 second
ACTUAL -
BUILD FAILED
java.lang.ExceptionInInitializerError
    at org.openjdk.nashorn.internal.runtime.Context.compile(Context.java:1509)
    at org.openjdk.nashorn.internal.runtime.Context.compileScript(Context.java:1449)
    at org.openjdk.nashorn.internal.runtime.Context.compileScript(Context.java:759)
    at org.openjdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:528)
    at org.openjdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:517)
    at org.openjdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:395)
    at org.openjdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:151)
    at java.scripting/javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:262)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.apache.tools.ant.util.ReflectUtil.invoke(ReflectUtil.java:108)
    at org.apache.tools.ant.util.ReflectWrapper.invoke(ReflectWrapper.java:81)
    at org.apache.tools.ant.util.optional.JavaxScriptRunner.evaluateScript(JavaxScriptRunner.java:103)
    at org.apache.tools.ant.util.optional.JavaxScriptRunner.executeScript(JavaxScriptRunner.java:67)
    at org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:52)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:392)
    at org.apache.tools.ant.Target.performTasks(Target.java:413)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.Main.runBuild(Main.java:811)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: no such method: sun.misc.Unsafe.defineAnonymousClass(Class,byte[],Object[])Class/invokeVirtual
    at org.openjdk.nashorn.internal.runtime.Context$AnonymousContextCodeInstaller.lambda$getDefineAnonymousClass$0(Context.java:335)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
    at org.openjdk.nashorn.internal.runtime.Context$AnonymousContextCodeInstaller.getDefineAnonymousClass(Context.java:327)
    at org.openjdk.nashorn.internal.runtime.Context$AnonymousContextCodeInstaller.<clinit>(Context.java:317)
    ... 33 more
Caused by: java.lang.NoSuchMethodException: no such method: sun.misc.Unsafe.defineAnonymousClass(Class,byte[],Object[])Class/invokeVirtual
    at java.base/java.lang.invoke.MemberName.makeAccessException(MemberName.java:976)
    at java.base/java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1117)
    at java.base/java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:3643)
    at java.base/java.lang.invoke.MethodHandles$Lookup.findVirtual(MethodHandles.java:2680)
    at org.openjdk.nashorn.internal.runtime.Context$AnonymousContextCodeInstaller.lambda$getDefineAnonymousClass$0(Context.java:329)
    ... 36 more
Caused by: java.lang.NoSuchMethodError: 'java.lang.Class sun.misc.Unsafe.defineAnonymousClass(java.lang.Class, byte[], java.lang.Object[])'
    at java.base/java.lang.invoke.MethodHandleNatives.resolve(Native Method)
    at java.base/java.lang.invoke.MemberName$Factory.resolve(MemberName.java:1085)
    at java.base/java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1114)
    ... 39 more

---------- BEGIN SOURCE ----------
See the "Steps to Reproduce" field
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None found

FREQUENCY : always



Comments
This was fixed in OpenJDK Nashorn 15.3, see JDK-8269602
07-12-2021

The observations on Windows 10: JDK 17ea+22: Passed. JDK 17ea+23: Failed, ExceptionInInitializerError JDK 18ea+1: Failed.
01-07-2021

Additional information from the submitter: Make sure to have the dependent jar files nashorn-core-15.2.jar in the C:\nashorn directory and asm-9.2.jar, asm-commons-9.2.jar, asm-tree-9.2.jar and asm-util-9.2.jar in the C:\asm directory (or modify the NashornTest.xml file to point to where those required jar files exist) The test runs successfully for me on Hotspot JDK 16.0.1, but fails on JDK 17. I also tried Hotspot 15 (15.0.2) and that also build successfully.
01-07-2021

Clarify with the submitter if the reproducer run successfully with other versions of Oracle JDK.
30-06-2021

Got the following result with JDK 17ea+6: C:\Users\tongwan\Documents\JI-9070780>c:\apache-ant-1.10.10\bin\ant -f NashornTest.xml step1 Buildfile: C:\Users\tongwan\Documents\JI-9070780\NashornTest.xml step1: BUILD FAILED C:\Users\tongwan\Documents\JI-9070780\NashornTest.xml:3: java.lang.NoClassDefFoundError: org/objectweb/asm/util/Printer at org.openjdk.nashorn.internal.codegen.Compiler.createCompileUnit(Compiler.java:766) at org.openjdk.nashorn.internal.codegen.Compiler.createCompileUnit(Compiler.java:774) at org.openjdk.nashorn.internal.codegen.Compiler.addCompileUnit(Compiler.java:759) at org.openjdk.nashorn.internal.codegen.CompilationPhase$SplittingPhase.transform(CompilationPhase.java:117) at org.openjdk.nashorn.internal.codegen.CompilationPhase.apply(CompilationPhase.java:614) at org.openjdk.nashorn.internal.codegen.Compiler.compile(Compiler.java:641) at org.openjdk.nashorn.internal.runtime.Context.compile(Context.java:1528) at org.openjdk.nashorn.internal.runtime.Context.compileScript(Context.java:1449) at org.openjdk.nashorn.internal.runtime.Context.compileScript(Context.java:759) at org.openjdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:528) at org.openjdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:517) at org.openjdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:395) at org.openjdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:151) at java.scripting/javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) at org.apache.tools.ant.util.optional.JavaxScriptRunner.evaluateScript(JavaxScriptRunner.java:154) at org.apache.tools.ant.util.optional.JavaxScriptRunner.executeScript(JavaxScriptRunner.java:86) at org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:53) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99) at org.apache.tools.ant.Task.perform(Task.java:350) at org.apache.tools.ant.Target.execute(Target.java:449) at org.apache.tools.ant.Target.performTasks(Target.java:470) at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1401) at org.apache.tools.ant.Project.executeTarget(Project.java:1374) at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) at org.apache.tools.ant.Project.executeTargets(Project.java:1264) at org.apache.tools.ant.Main.runBuild(Main.java:827) at org.apache.tools.ant.Main.startAnt(Main.java:223) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101) Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.util.Printer at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1383) at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1338) at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1093) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519) ... 34 more Total time: 0 seconds
30-06-2021