Minecraftforge: Forge fails to load classes with packages starting with javax.

Created on 10 Aug 2019  路  11Comments  路  Source: MinecraftForge/MinecraftForge


Minecraft Version: 1.13.2

Forge Version: 1.13.2-25.0.219

Logs: (Using https://github.com/wizards-of-lua/wizards-of-lua/tree/137ab9e7b6ffa24f1f3044713ade172680ac9816)

2019-08-10 16:01:23,174 main WARN Disabling terminal, you're running in an unsupported environment.
[16:01:23.263] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 25.0.219, --fml.mcpVersion, 20190213.203750, --fml.mcVersion, 1.13.2, --fml.forgeGroup, net.minecraftforge]
[16:01:23.266] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher starting: java version 1.8.0_212
[16:01:23.585] [main/INFO] [ne.mi.fm.lo.FixSSL/CORE]: Added Lets Encrypt root certificates as additional trust
[16:01:23.878] [main/INFO] [cp.mo.mo.LaunchServiceHandler/MODLAUNCHER]: Launching target 'fmlserver' with arguments [--gameDir, .]
[16:01:30.569] [main/WARN] [minecraft/Commands]: Ambiguity between arguments [teleport, destination] and [teleport, targets] with inputs: [Player, 0123, @e, dd12be42-52a9-4a91-a8a1-11c01849e498]
[16:01:30.582] [main/WARN] [minecraft/Commands]: Ambiguity between arguments [teleport, location] and [teleport, destination] with inputs: [0.1 -0.5 .9, 0 0 0]
[16:01:30.584] [main/WARN] [minecraft/Commands]: Ambiguity between arguments [teleport, location] and [teleport, targets] with inputs: [0.1 -0.5 .9, 0 0 0]
[16:01:30.588] [main/WARN] [minecraft/Commands]: Ambiguity between arguments [teleport, targets] and [teleport, destination] with inputs: [Player, 0123, dd12be42-52a9-4a91-a8a1-11c01849e498]
[16:01:30.590] [main/WARN] [minecraft/Commands]: Ambiguity between arguments [teleport, targets, location] and [teleport, targets, destination] with inputs: [0.1 -0.5 .9, 0 0 0]
[16:01:30.812] [main/INFO] [minecraft/RecipeManager]: Loaded 0 recipes
[16:01:30.815] [main/INFO] [minecraft/AdvancementList]: Loaded 0 advancements
[16:01:31.777] [Server thread/INFO] [minecraft/DedicatedServer]: Starting minecraft server version 1.13.2
[16:01:31.875] [Server thread/INFO] [ne.mi.fm.ModLoader/CORE]: Loading Network data for FML net version: FML2
[16:01:31.955] [modloading-worker-2/INFO] [ne.wi.WizardsOfLua/]: Initializing Wizards-of-Lua, Version @MOD_VERSION@
[16:01:31.968] [modloading-worker-1/INFO] [ne.mi.co.ForgeMod/FORGEMOD]: Forge mod loading, version 25.0.219, for MC 1.13.2 with MCP 20190213.203750
[16:01:31.969] [modloading-worker-1/INFO] [ne.mi.co.MinecraftForge/FORGE]: MinecraftForge v25.0.219 Initialized
[16:01:31.966] [modloading-worker-2/ERROR] [ne.mi.fm.ja.FMLModContainer/LOADING]: Failed to create mod instance. ModID: wol, class net.wizardsoflua.WizardsOfLua
java.lang.NoClassDefFoundError: javax/inject/Singleton
        at net.wizardsoflua.extension.InjectionScope.<init>(InjectionScope.java:55) ~[?:?] {pl:eventbus:A,pl:object_holder_definalize:A,pl:runtime_enum_extender:A,pl:capability_inject_definalize:A,pl:runtimedistcleaner:A}
        at net.wizardsoflua.WizardsOfLua.createRootScope(WizardsOfLua.java:45) ~[?:?] {pl:eventbus:A,pl:object_holder_definalize:A,pl:runtime_enum_extender:A,pl:capability_inject_definalize:A,pl:runtimedistcleaner:A}
        at net.wizardsoflua.WizardsOfLua.<init>(WizardsOfLua.java:37) ~[?:?] {pl:eventbus:A,pl:object_holder_definalize:A,pl:runtime_enum_extender:A,pl:capability_inject_definalize:A,pl:runtimedistcleaner:A}
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_212] {}
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_212] {}
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_212] {}
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_212] {}
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_212] {}
        at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:130) ~[?:25.0] {pl:eventbus:A,pl:object_holder_definalize:A,pl:runtime_enum_extender:A,pl:capability_inject_definalize:A,pl:runtimedistcleaner:A}
        at java.util.function.Consumer.lambda$andThen$0(Unknown Source) ~[?:1.8.0_212] {}
        at java.util.function.Consumer.lambda$andThen$0(Unknown Source) ~[?:1.8.0_212] {}
        at net.minecraftforge.fml.ModContainer.transitionState(ModContainer.java:111) ~[?:?] {pl:eventbus:A,pl:object_holder_definalize:A,pl:runtime_enum_extender:A,pl:capability_inject_definalize:A,pl:runtimedistcleaner:A}
        at net.minecraftforge.fml.ModList.lambda$null$9(ModList.java:120) ~[?:?] {pl:eventbus:A,pl:object_holder_definalize:A,pl:runtime_enum_extender:A,pl:capability_inject_definalize:A,pl:runtimedistcleaner:A}
        at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(Unknown Source) [?:1.8.0_212] {}
        at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source) [?:1.8.0_212] {}
        at java.util.stream.AbstractPipeline.copyInto(Unknown Source) [?:1.8.0_212] {}
        at java.util.stream.ForEachOps$ForEachTask.compute(Unknown Source) [?:1.8.0_212] {}
        at java.util.concurrent.CountedCompleter.exec(Unknown Source) [?:1.8.0_212] {}
        at java.util.concurrent.ForkJoinTask.doExec(Unknown Source) [?:1.8.0_212] {}
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(Unknown Source) [?:1.8.0_212] {}
        at java.util.concurrent.ForkJoinPool.runWorker(Unknown Source) [?:1.8.0_212] {}
        at java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source) [?:1.8.0_212] {}
Caused by: java.lang.ClassNotFoundException: javax.inject.Singleton
        at java.lang.ClassLoader.findClass(Unknown Source) ~[?:1.8.0_212] {}
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_212] {}
        at cpw.mods.modlauncher.TransformingClassLoader.loadClass(TransformingClassLoader.java:75) ~[modlauncher-2.1.1.jar:?] {}
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_212] {}
        ... 22 more
[16:01:32.175] [Server thread/FATAL] [ne.mi.fm.ModLoader/LOADING]: Failed to complete lifecycle event CONSTRUCT, 1 errors found
[16:01:32.176] [Server thread/ERROR] [minecraft/MinecraftServer]: Encountered an unexpected exception
net.minecraftforge.fml.LoadingFailedException: null
        at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:157) ~[?:?] {pl:eventbus:A,pl:object_holder_definalize:A,pl:runtime_enum_extender:A,pl:capability_inject_definalize:A,pl:runtimedistcleaner:A}
        at net.minecraftforge.fml.ModLoader.loadMods(ModLoader.java:137) ~[?:?] {pl:eventbus:A,pl:object_holder_definalize:A,pl:runtime_enum_extender:A,pl:capability_inject_definalize:A,pl:runtimedistcleaner:A}
        at net.minecraftforge.fml.server.ServerModLoader.begin(ServerModLoader.java:44) ~[?:?] {pl:eventbus:A,pl:object_holder_definalize:A,pl:runtime_enum_extender:A,pl:capability_inject_definalize:A,pl:runtimedistcleaner:A}
        at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:116) ~[?:?] {pl:accesstransformer:B,pl:object_holder_definalize:A,pl:runtime_enum_extender:A,pl:capability_inject_definalize:A,pl:runtimedistcleaner:A}
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:549) [?:?] {pl:accesstransformer:B,pl:object_holder_definalize:A,pl:runtime_enum_extender:A,pl:capability_inject_definalize:A,pl:runtimedistcleaner:A}
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_212] {}
[16:01:32.194] [Server thread/ERROR] [minecraft/MinecraftServer]: This crash report has been saved to: C:\Users\Adrodoc\devel\workspace\wol-server-1.13.2\.\crash-reports\crash-2019-08-10_16.01.32-server.txt
[16:01:32.215] [Server thread/INFO] [minecraft/MinecraftServer]: Stopping server
[16:01:32.215] [Server thread/INFO] [minecraft/MinecraftServer]: Saving worlds
[16:01:32.220] [Server Shutdown Thread/INFO] [minecraft/MinecraftServer]: Stopping server
[16:01:32.221] [Server Shutdown Thread/INFO] [minecraft/MinecraftServer]: Saving worlds

Steps to Reproduce:

  1. Build jar file with gradlew jar
  2. Copy the jar file build/libs/wol-1.13.2-3.0.0.jar into a forge server installation
  3. Start the server

Description of issue:
Forge fails to load the class javax.inject.Singleton which is contained in the mod-jar-file. This happens because the method TransformingClassLoader.loadClass(String, boolean) avoids loading certain classes from mod-jar-files, in particular classes with packages starting with javax..
This is a problem, because there are many libraries that use packages that start with javax., including but not limited to:

  • javax.inject:javax.inject:1
  • javax.enterprise:cdi-api:2.0 and with that org.jboss.weld.se:weld-se:2.4.8.Final
  • com.google.code.findbugs:jsr305:3.0.2

I think a relatively simple fix could be to catch the ClassNotFoundException in TransformingClassLoader:75 and try loading the class with the classBytesFinder like this:

protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
  synchronized (getClassLoadingLock(name)) {
    if (!targetPackageFilter.test(name)) {
      LOGGER.trace(CLASSLOADING, "Delegating to parent {}", name);
      try {
        return super.loadClass(name, resolve);
      } catch (ClassNotFoundException e) {
        try {
          LOGGER.trace(CLASSLOADING, "Attempting to load {}", name);
          final Class<?> loadedClass = loadClass(name, this.classBytesFinder);
          LOGGER.trace(CLASSLOADING, "Class loaded for {}", name);
          return loadedClass;
        } catch (ClassNotFoundException e2) {
          e2.addSuppressed(e);
          throw e2;
        }
      }
    } else {
      try {
        LOGGER.trace(CLASSLOADING, "Attempting to load {}", name);
        final Class<?> loadedClass = loadClass(name, this.classBytesFinder);
        LOGGER.trace(CLASSLOADING, "Class loaded for {}", name);
        return loadedClass;
      } catch (ClassNotFoundException | SecurityException e) {
        LOGGER.trace(CLASSLOADING, "Delegating to parent {}", name);
        return super.loadClass(name, resolve);
      }
    }
  }
}

It seems to me like this approach would also make the targetPackageFilter redundant, so maybe that can be removed entirely?

Triage

Most helpful comment

I'm pretty sure 1.13 is already long dead. I would suggest trying this on 1.14.4 and see if the issue still persists there.

All 11 comments

Did you go to https://github.com/wizards-of-lua/wizards-of-lua/tree/137ab9e7b6ffa24f1f3044713ade172680ac9816 ???

and went to the issue page? Because the way I see this, is that it is on their side

@FinnT730 I am the developer of that mod

oh.... sorry, didn't know, then forget that I said anything at all!

I'm pretty sure 1.13 is already long dead. I would suggest trying this on 1.14.4 and see if the issue still persists there.

@GirafiStudios I can try, but the responsible code in TransformingClassLoader hasn't changed, so it is very likely the issue persists.

As suspected the issue persists in 1.14.
Here is a reproducer for forge 1.14.4-28.0.45: https://github.com/Adrodoc/minecraft-forge-6025-reproducer.
As you can see in the log (in the README of the repo) the class org.jboss.weld.environment.se.Weld can be loaded, but the class javax.inject.Singleton can't.

Just noting, this has previously been reported as cpw/modlauncher/issues/27

There are more related previous issues, now since closed, as shading is generally the course to take.

Shading is preferred. Though I might need to allow some inject related stuff from javax.

@cpw we are using shading as a workaround, but this prevents other projects from using us as a library, because we use jaxax classes in our API. We would have to release the shaded jar files, and reconstruct the source code to allow others to program with our API which is annoying.

Why are you using javax in your API? Also, this is better handled in the modlauncher repo, not here.

We use it in the API, because we want users to be able to inject some of our services with the normal @Inject annotation

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MJRLegends picture MJRLegends  路  3Comments

DaedalusGame picture DaedalusGame  路  3Comments

NovaViper picture NovaViper  路  3Comments

williewillus picture williewillus  路  3Comments

MSandro picture MSandro  路  3Comments