When using Nashorn 15.3 as a module, script engine is undefined in plugins

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Minor
    • None
    • Affects Version/s: None
    • Environment:
    • CraftBukkit version 3405-Spigot-f4ff00f-d10c35e (MC: 1.18.1) (Implementing API version 1.18.1-R0.1-SNAPSHOT)
    • Yes

      Previously in 1.17.1 on openjdk16 & openjdk17 the Nashorn JavaScript engine was found and worked as expected.

      Now in 1.18.1 on openjdk17 the Nashorn engine is undefined.

      Again, Nashorn 15.3 is NOT included in openjdk17 and is loaded as a module via:

      java -Xms512M -Xmx1G -cp /minecraft/nashorn --module-path /minecraft/nashorn --add-modules org.openjdk.nashorn -jar spigot-1.18.1.jar 

       

      It seems plugin behavior has changed between 1.17.1 and 1.18.1.

       

      Outside of Spigot, the referenced NashornTest.java CAN access the Nashorn engine and produces this output:

       

      java -cp /minecraft/nashorn -cp . --module-path /minecraft/nashorn --add-modules org.openjdk.nashorn NashornTest
      
      VM Details:
      OpenJDK 64-Bit Server VM
      17.0.1+12-39
      mixed mode, sharing
      Nashorn engine found!
      ECMAScript OpenJDK Nashorn [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript]

      Note: /minecraft/nashorn contains the Nashorn 15.3 jars (https://search.maven.org/artifact/org.openjdk.nashorn/nashorn-core/15.3/jar)

      https://github.com/wwlib/docker-minecraft/blob/master/minecraft-server-1.18.1-openjdk17/plugins/nashorn-test/NashornTest.java

      As noted above, previously from within a plugin loaded by 1.17.1 the Nashorn engine CAN be accessed. (java16 and java17)

      However, from within a plugin loaded by 1.18.1 the Nashorn engine CANNOT be accessed. (java17)

      Example plugin:

      https://github.com/wwlib/docker-minecraft/blob/master/minecraft-server-1.18.1-openjdk17/plugins/plugin-javascript/plugin/org/wwlib/spigotmc/HelloJavaScript/Main.java

      Produces the error: "No JavaScript Engine available."

       

      Is this related to:

      https://hub.spigotmc.org/jira/browse/SPIGOT-6822

          [SPIGOT-6902] When using Nashorn 15.3 as a module, script engine is undefined in plugins

          wwlib added a comment - - edited

          Update re: Grakkit

          Just an FYI unrelated to the original issue (but interesting)

          It turns out that Grakkit DOES work in 1.18.1 when using openjdk17 WITHOUT GraalVM: i.e. openjdk:17-oraclelinux8

          (https://github.com/wwlib/docker-minecraft/blob/master/minecraft-server-1.18.1-openjdk17/Dockerfile.openjdk17)

          It turns out that Grakkit does not use ScriptEngine. It packages and shades the GraalJS library and uses those classes.

          What does not work is the combo of GraalVM CE 21.3.0 (ghcr.io/graalvm/graalvm-ce:java17-21.3) + 1.18.1 + Grakkit.

          wwlib added a comment - - edited Update re: Grakkit Just an FYI unrelated to the original issue (but interesting) It turns out that Grakkit DOES work in 1.18.1 when using openjdk17 WITHOUT GraalVM: i.e. openjdk:17-oraclelinux8 ( https://github.com/wwlib/docker-minecraft/blob/master/minecraft-server-1.18.1-openjdk17/Dockerfile.openjdk17) It turns out that Grakkit does not use ScriptEngine. It packages and shades the GraalJS library and uses those classes. What does not work is the combo of GraalVM CE 21.3.0 (ghcr.io/graalvm/graalvm-ce:java17-21.3) + 1.18.1 + Grakkit.

          wwlib added a comment -

          Great. Thanks, again.

          wwlib added a comment - Great. Thanks, again.

          md_5 added a comment -

          md_5 added a comment - Yes Not sure, see 'Library Loader' in plugin.yml: https://www.spigotmc.org/threads/spigot-bungeecord-1-17-1-17-1.510208/#post-4184317 Yes

          wwlib added a comment -

          Checking to see if I understand:

          • Shaded script engine
            • Do you mean packaging the plugin so its dependencies are shaded?
          • Library loaded script
            • Assume this is what Grakkit does by including the GraalVM classes in its plugin jar
          • Module loaded script engine
            • Assume this refers to loading Nashorn 15.3 - as a module:
              • --module-path /minecraft/nashorn --add-modules org.openjdk.nashorn

          Do any of these describe the script engine included in the GraalVM openjdk 17 distribution? 

          "Module loaded script engine is now fixed" this sounds promising, though maybe temporary.

          wwlib added a comment - Checking to see if I understand: Shaded script engine Do you mean packaging the plugin so its dependencies are shaded? Library loaded script Assume this is what Grakkit does by including the GraalVM classes in its plugin jar Module loaded script engine Assume this refers to loading Nashorn 15.3 - as a module: --module-path /minecraft/nashorn --add-modules org.openjdk.nashorn Do any of these describe the script engine included in the GraalVM openjdk 17 distribution?  "Module loaded script engine is now fixed" this sounds promising, though maybe temporary.

          md_5 added a comment - - edited

          I dug into this for you, and the situation is:

          • Shaded script engine works as normal
          • Library loaded script engine doesn't work due to SPIGOT-6904
          • Module loaded script engine is now fixed (though I would discourage this, I don't like the behaviour and may remove it once SPIGOT-6904 is fixed)

          md_5 added a comment - - edited I dug into this for you, and the situation is: Shaded script engine works as normal Library loaded script engine doesn't work due to SPIGOT-6904 Module loaded script engine is now fixed (though I would discourage this, I don't like the behaviour and may remove it once SPIGOT-6904 is fixed)

          wwlib added a comment -

          (Cross-posted. Just seeing your previous reply.)

          "The main spigot-1.18.jar is now a bootstrap jar which contains all libraries." etc.

          "I suggest you ask the forums for help"

          OK, will do.

          Thanks for the help. 

          wwlib added a comment - (Cross-posted. Just seeing your previous reply.) "The main spigot-1.18.jar is now a bootstrap jar which contains all libraries." etc. "I suggest you ask the forums for help" OK, will do. Thanks for the help. 

          wwlib added a comment -

          FYI: I just tested another plugin (grakkit) that uses JavaScript by including GraalVM dependencies in its plugin jar (grakkit-5.0.4.paper.jar).

          https://github.com/grakkit/grakkit

          Same issue. Grakkit works in spigot-1.17.1 but fails in spigot-1.18.1 (also fails using paper-1.18.1-155.jar)

           

          [21:32:21] [Server thread/WARN]: [grakkit] Task #2 for grakkit v5.0.4 generated an exception
          java.lang.NullPointerException: Cannot invoke "grakkit.FileInstance.tick()" because "grakkit.Grakkit.driver" is null
                  at grakkit.Grakkit.tick(Grakkit.java:93) ~[grakkit-5.0.4.paper.jar:?]
                  at org.bukkit.craftbukkit.v1_18_R1.scheduler.CraftTask.run(CraftTask.java:82) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3405-Spigot-f4ff00f-d10c35e]
                  at org.bukkit.craftbukkit.v1_18_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:415) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3405-Spigot-f4ff00f-d10c35e]
                  at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1255) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3405-Spigot-f4ff00f-d10c35e]
                  at net.minecraft.server.dedicated.DedicatedServer.b(DedicatedServer.java:428) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3405-Spigot-f4ff00f-d10c35e]
                  at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:1206) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3405-Spigot-f4ff00f-d10c35e]
                  at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1034) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3405-Spigot-f4ff00f-d10c35e]
                  at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:304) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3405-Spigot-f4ff00f-d10c35e]

          wwlib added a comment - FYI: I just tested another plugin (grakkit) that uses JavaScript by including GraalVM dependencies in its plugin jar (grakkit-5.0.4.paper.jar). https://github.com/grakkit/grakkit Same issue. Grakkit works in spigot-1.17.1 but fails in spigot-1.18.1 (also fails using paper-1.18.1-155.jar)   [21:32:21] [Server thread/WARN] : [grakkit] Task #2 for grakkit v5.0.4 generated an exception java.lang.NullPointerException: Cannot invoke "grakkit.FileInstance.tick()" because "grakkit.Grakkit.driver" is null         at grakkit.Grakkit.tick(Grakkit.java:93) ~ [grakkit-5.0.4.paper.jar:?]         at org.bukkit.craftbukkit.v1_18_R1.scheduler.CraftTask.run(CraftTask.java:82) ~ [spigot-1.18.1-R0.1-SNAPSHOT.jar:3405-Spigot-f4ff00f-d10c35e]         at org.bukkit.craftbukkit.v1_18_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:415) ~ [spigot-1.18.1-R0.1-SNAPSHOT.jar:3405-Spigot-f4ff00f-d10c35e]         at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1255) ~ [spigot-1.18.1-R0.1-SNAPSHOT.jar:3405-Spigot-f4ff00f-d10c35e]         at net.minecraft.server.dedicated.DedicatedServer.b(DedicatedServer.java:428) ~ [spigot-1.18.1-R0.1-SNAPSHOT.jar:3405-Spigot-f4ff00f-d10c35e]         at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:1206) ~ [spigot-1.18.1-R0.1-SNAPSHOT.jar:3405-Spigot-f4ff00f-d10c35e]         at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1034) ~ [spigot-1.18.1-R0.1-SNAPSHOT.jar:3405-Spigot-f4ff00f-d10c35e]         at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:304) ~ [spigot-1.18.1-R0.1-SNAPSHOT.jar:3405-Spigot-f4ff00f-d10c35e]

          md_5 added a comment - - edited

          Bootstrap Jar
          The main spigot-1.18.jar is now a bootstrap jar which contains all libraries. You cannot directly depend on this jar. You should depend on Spigot/Spigot-API/target/spigot-api-1.18-R0.1-SNAPSHOT-shaded.jar, or the entire contents of the bundler directory from your server, or use a dependency manager such as Maven or Gradle to handle this automatically.

          Please read the release notes for further information: https://www.spigotmc.org/threads/9-years-of-spigotmc-spigot-bungeecord-1-18-1-18-1-release.534760/#post-4305163

          I suggest you ask the forums for help, as I do not believe there to be any Spigot bug. If you believe there is a bug with how Spigot loads classes (unlikely), then please create a minimal test case using one of the supported methods (shaded jar, library loader). It is outside the scope of a bug report here to debug the entirety of Nashorn (especially when loaded in an unsupported manner).

          md_5 added a comment - - edited Bootstrap Jar The main spigot-1.18.jar is now a bootstrap jar which contains all libraries. You cannot directly depend on this jar. You should depend on Spigot/Spigot-API/target/spigot-api-1.18-R0.1-SNAPSHOT-shaded.jar, or the entire contents of the bundler directory from your server, or use a dependency manager such as Maven or Gradle to handle this automatically. Please read the release notes for further information: https://www.spigotmc.org/threads/9-years-of-spigotmc-spigot-bungeecord-1-18-1-18-1-release.534760/#post-4305163 I suggest you ask the forums for help, as I do not believe there to be any Spigot bug. If you believe there is a bug with how Spigot loads classes (unlikely), then please create a minimal test case using one of the supported methods (shaded jar, library loader). It is outside the scope of a bug report here to debug the entirety of Nashorn (especially when loaded in an unsupported manner).

          wwlib added a comment - - edited

          For reference (completeness) the same issue happens when running spigot-1.18.1 using GraalVM (openjdk17 + Graal Script Engine)
           
          Using container image: ghcr.io/graalvm/graalvm-ce:java17-21.3 from https://github.com/graalvm/container/pkgs/container/graalvm-ce
           
          Dockerfile:
          https://github.com/wwlib/docker-minecraft/blob/master/minecraft-server-1.18.1-openjdk17/Dockerfile.openjdk17-graalvm
           

          java --version
          openjdk 17.0.1 2021-10-19
          OpenJDK Runtime Environment GraalVM CE 21.3.0 (build 17.0.1+12-jvmci-21.3-b05)
          OpenJDK 64-Bit Server VM GraalVM CE 21.3.0 (build 17.0.1+12-jvmci-21.3-b05, mixed mode, sharing)

          When running GraalVM (openjdk17) Minecraft 1.17.1 CAN access the JavaScript script engine.

          1.17.1

          java -Xms512M -Xmx1G -jar spigot-1.17.1.jar

          [19:20:06] [Worker-Main-10/INFO]: Preparing spawn area: 91%
          [19:20:06] [Server thread/INFO]: Time elapsed: 3874 ms
          [19:20:06] [Server thread/INFO]: [hellojavascript] Enabling hellojavascript v0.1
          [19:20:06] [Server thread/ERROR]: [hellojavascript] HelloJavaScript plugin enabled.
          [19:20:06] [Server thread/ERROR]: [hellojavascript] VM Details:
          [19:20:06] [Server thread/ERROR]: [hellojavascript] OpenJDK 64-Bit Server VM
          [19:20:06] [Server thread/ERROR]: [hellojavascript] 17.0.1+12-jvmci-21.3-b05
          [19:20:06] [Server thread/ERROR]: [hellojavascript] mixed mode, sharing
          [19:20:07] [Server thread/ERROR]: [hellojavascript] Found a JavaScript engine.
          [19:20:07] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
          [19:20:07] [Server thread/INFO]: Done (35.591s)! For help, type "help"

          When running GraalVM (openjdk17) Minecraft 1.18.1 CANNOT access the JavaScript script engine.

          1.18.1

          java -Xms512M -Xmx1G -jar spigot-1.18.1.jar

          [19:29:50] [Worker-Main-8/INFO]: Preparing spawn area: 97%
          [19:29:51] [Server thread/INFO]: Time elapsed: 7584 ms
          [19:29:51] [Server thread/INFO]: [hellojavascript] Enabling hellojavascript v0.1
          [19:29:51] [Server thread/ERROR]: [hellojavascript] HelloJavaScript plugin enabled.
          [19:29:51] [Server thread/ERROR]: [hellojavascript] VM Details:
          [19:29:51] [Server thread/ERROR]: [hellojavascript] OpenJDK 64-Bit Server VM
          [19:29:51] [Server thread/ERROR]: [hellojavascript] 17.0.1+12-jvmci-21.3-b05
          [19:29:51] [Server thread/ERROR]: [hellojavascript] mixed mode, sharing
          [19:29:51] [Server thread/ERROR]: [hellojavascript] No JavaScript Engine available.
          [19:29:51] [Server thread/ERROR]: [hellojavascript] Available engines include:
          [19:29:51] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
          [19:29:51] [Server thread/INFO]: Done (103.668s)! For help, type "help"
           
           
          @md_5: Is this also explained by: "the Spigot jars are not loaded into the system classloader" and is this because class loading has changed between 1.17.1 and 1.18.1 ?

          wwlib added a comment - - edited For reference (completeness) the same issue happens when running spigot-1.18.1 using GraalVM (openjdk17 + Graal Script Engine)   Using container image: ghcr.io/graalvm/graalvm-ce:java17-21.3 from https://github.com/graalvm/container/pkgs/container/graalvm-ce   Dockerfile: https://github.com/wwlib/docker-minecraft/blob/master/minecraft-server-1.18.1-openjdk17/Dockerfile.openjdk17-graalvm   java --version openjdk 17.0.1 2021-10-19 OpenJDK Runtime Environment GraalVM CE 21.3.0 (build 17.0.1+12-jvmci-21.3-b05) OpenJDK 64-Bit Server VM GraalVM CE 21.3.0 (build 17.0.1+12-jvmci-21.3-b05, mixed mode, sharing) When running GraalVM (openjdk17) Minecraft 1.17.1 CAN access the JavaScript script engine. 1.17.1 java -Xms512M -Xmx1G -jar spigot-1.17.1.jar [19:20:06] [Worker-Main-10/INFO] : Preparing spawn area: 91% [19:20:06] [Server thread/INFO] : Time elapsed: 3874 ms [19:20:06] [Server thread/INFO] : [hellojavascript] Enabling hellojavascript v0.1 [19:20:06] [Server thread/ERROR] : [hellojavascript] HelloJavaScript plugin enabled. [19:20:06] [Server thread/ERROR] : [hellojavascript] VM Details: [19:20:06] [Server thread/ERROR] : [hellojavascript] OpenJDK 64-Bit Server VM [19:20:06] [Server thread/ERROR] : [hellojavascript] 17.0.1+12-jvmci-21.3-b05 [19:20:06] [Server thread/ERROR] : [hellojavascript] mixed mode, sharing [19:20:07] [Server thread/ERROR] : [hellojavascript] Found a JavaScript engine. [19:20:07] [Server thread/INFO] : Server permissions file permissions.yml is empty, ignoring it [19:20:07] [Server thread/INFO] : Done (35.591s)! For help, type "help" When running GraalVM (openjdk17) Minecraft 1.18.1 CANNOT access the JavaScript script engine. 1.18.1 java -Xms512M -Xmx1G -jar spigot-1.18.1.jar [19:29:50] [Worker-Main-8/INFO] : Preparing spawn area: 97% [19:29:51] [Server thread/INFO] : Time elapsed: 7584 ms [19:29:51] [Server thread/INFO] : [hellojavascript] Enabling hellojavascript v0.1 [19:29:51] [Server thread/ERROR] : [hellojavascript] HelloJavaScript plugin enabled. [19:29:51] [Server thread/ERROR] : [hellojavascript] VM Details: [19:29:51] [Server thread/ERROR] : [hellojavascript] OpenJDK 64-Bit Server VM [19:29:51] [Server thread/ERROR] : [hellojavascript] 17.0.1+12-jvmci-21.3-b05 [19:29:51] [Server thread/ERROR] : [hellojavascript] mixed mode, sharing [19:29:51] [Server thread/ERROR] : [hellojavascript] No JavaScript Engine available. [19:29:51] [Server thread/ERROR] : [hellojavascript] Available engines include: [19:29:51] [Server thread/INFO] : Server permissions file permissions.yml is empty, ignoring it [19:29:51] [Server thread/INFO] : Done (103.668s)! For help, type "help"     @md_5: Is this also explained by: "the Spigot jars are not loaded into the system classloader" and is this because class loading has changed between 1.17.1 and 1.18.1 ?

          wwlib added a comment -

          OK. Can you confirm that this is a change from 1.17.1 since it worked there.

          I will look into loading Nashorn using the library loader, as you suggest.

          And just to make sure I am seeing all the release notes, I have reviewed the notes here:

          https://www.spigotmc.org/threads/9-years-of-spigotmc-spigot-bungeecord-1-18-1-18-1-release.534760/

          And looked at the diff here:

          https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/compare/diff?targetBranch=d32e3c764edd6a449ddd220720185d266c2193f9&sourceBranch=refs%2Fheads%2Fmaster&targetRepoId=11

          Are there other notes? I did not see a mention of a plugin loading change - at least not a breaking change. (But I am new to this)

          Thanks.

          wwlib added a comment - OK. Can you confirm that this is a change from 1.17.1 since it worked there. I will look into loading Nashorn using the library loader, as you suggest. And just to make sure I am seeing all the release notes, I have reviewed the notes here: https://www.spigotmc.org/threads/9-years-of-spigotmc-spigot-bungeecord-1-18-1-18-1-release.534760/ And looked at the diff here: https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/compare/diff?targetBranch=d32e3c764edd6a449ddd220720185d266c2193f9&sourceBranch=refs%2Fheads%2Fmaster&targetRepoId=11 Are there other notes? I did not see a mention of a plugin loading change - at least not a breaking change. (But I am new to this) Thanks.

            Assignee:
            Unassigned
            Reporter:
            wwlib
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: