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

ExceptionInInitializerError trying to use nashorn 15.1.1 or 15.2 with Java 17+27

    XMLWordPrintable

Details

    • b23
    • 17

    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


      Attachments

        1. NashornTest.xml
          0.5 kB
          Andrew Wang

        Issue Links

          Activity

            People

              attila Attila Szegedi
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: