1.17.x [14:57:11 WARN]: java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics while class exists

Discussion in 'Spigot Plugin Development' started by eirikh1996, Jun 28, 2021.

  1. Hello. I have once again encountered an issue with a plugin that I have written in Kotlin. When trying to enable its expansions, which are jars that expand the plugin's functionality, however, this error shows up, even though the class in question, along with the entirety of the Kotlin library is shaded into the plugin JAR

    Code (Text):
    [14:57:11 INFO]: [Movecraft-Space] [DynmapExpansion]ERROR: Failure to enable expansion DynmapExpansion
    [14:57:11 WARN]: java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
    [14:57:11 WARN]:        at io.github.eirikh1996.movecraftspace.expansion.dynmap.DynmapExpansion$enable$1.<init>(DynmapExpansion.kt:45)
    [14:57:11 WARN]:        at io.github.eirikh1996.movecraftspace.expansion.dynmap.DynmapExpansion.enable(DynmapExpansion.kt:42)
    [14:57:11 WARN]:        at io.github.eirikh1996.movecraftspace.expansion.Expansion.setState(Expansion.kt:56)
    [14:57:11 WARN]:        at io.github.eirikh1996.movecraftspace.expansion.ExpansionManager.enableExpansions(ExpansionManager.kt:153)
    [14:57:11 WARN]:        at io.github.eirikh1996.movecraftspace.MovecraftSpace$onEnable$2.run(MovecraftSpace.kt:68)
    [14:57:11 WARN]:        at org.bukkit.craftbukkit.v1_17_R1.scheduler.CraftTask.run(CraftTask.java:100)
    [14:57:11 WARN]:        at org.bukkit.craftbukkit.v1_17_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:468)
    [14:57:11 WARN]:        at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1488)
    [14:57:11 WARN]:        at net.minecraft.server.dedicated.DedicatedServer.b(DedicatedServer.java:477)
    [14:57:11 WARN]:        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:1404)
    [14:57:11 WARN]:        at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:1180)
    [14:57:11 WARN]:        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:320)
    [14:57:11 WARN]:        at java.base/java.lang.Thread.run(Thread.java:831)
    [14:57:11 WARN]: Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics
    [14:57:11 WARN]:        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:433)
    [14:57:11 WARN]:        at io.github.eirikh1996.movecraftspace.expansion.ExpansionClassLoader.findClass(ExpansionClassLoader.kt:80)
    [14:57:11 WARN]:        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:586)
    [14:57:11 WARN]:        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
    [14:57:11 WARN]:        ... 13 more
    Code of the expansion class: https://pastebin.com/kdb6gSPS

    Code of ExpansionClassLoader: https://pastebin.com/2nYPNaZL

    Plugin POM: https://pastebin.com/jAZFXeuF

    Server details:
    Version: [16:10:34 INFO]: This server is running Paper version git-Paper-53 (MC: 1.17) (Implementing API version 1.17-R0.1-SNAPSHOT) (Git: 0ad5526)
    Java version: 16
    Plugins: [16:11:39 INFO]: Plugins (9): dynmap*, Essentials, EssentialsSpawn, Movecraft, Movecraft-Space, Multiverse-Core, TerraformGenerator, void-generator, WorldEdit

    I tested the same code on both 1.12.2 and 1.16.5 and it does work there. On 1.17, however, it was a completely different story. What is wrong here?
  2. You need to shade the Kotlin runtime dependencies as well.
  3. And how do I do that? I have already shaded the stdlib, which contains the runtime classes, including the "missing" class in question. Are there som other libraries I need to add?
  4. The pom doesn't show that you're shading the runtime and std lib.
  5. Perhaps it's a problem with relocation? In your picture, the classes were relocated to io.github.eirikh1996.movecraftspace.kotlinlib.jvm, but the server is still trying to load them from kotlin.jvm.
    • Useful Useful x 1
  6. Yeah that's a good idea. The Library feature of 1.16.5 or 1.17 is worth a look as well.
  7. A little update here: It did some debugging on the class loader and on 1.17, it seems to attempt to find said class when it tries to create an object extending BukkitRunnable within the enable method, on 1.16.5 and below, the ExpansionClassLoader.findClass method is not even called for finding the Kotlin class that is causing issues.
  8. Tried both of those. Nothing changed
  9. You need to shade the Kotlin runtime dependencies
  10. Is that the kotlin.jvm stuff?
  11. I dont know. I didnt use kotlin