Jump to content

[1.12.2] Strange case of java.lang.NoClassDefFoundError on server


Aarilight

Recommended Posts

My mod works fine in singleplayer and on a lan server hosted from a client, but as soon as I try to run a dedicated server it crashes when trying to register items. This sounds like it would be a @SideOnly bug, but the class it can't find is my class yuudaari.soulus.common.ModItems, which is a basic class, obviously, since it's all my mod's items. I have no idea why it wouldn't exist on a server...
 

Here's the full error:

java.lang.NoClassDefFoundError: Could not initialize class yuudaari.soulus.common.ModItems
     at yuudaari.soulus.Soulus.registerItems(Soulus.java:133) ~[Soulus.class:?]
     at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_18_Soulus_registerItems_Register.invoke(.dynamic) ~[?:?]
 at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?]
       at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:143) ~[EventBus$1.class:?]
       at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179) ~[EventBus.class:?]
     at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:741) ~[GameData.class:?]
    at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:603) ~[Loader.class:?]
   at net.minecraftforge.fml.server.FMLServerHandler.beginServerLoading(FMLServerHandler.java:98) ~[FMLServerHandler.class:?]
     at net.minecraftforge.fml.common.FMLCommonHandler.onServerStart(FMLCommonHandler.java:331) ~[FMLCommonHandler.class:?]
 at net.minecraft.server.dedicated.DedicatedServer.init(DedicatedServer.java:128) ~[DedicatedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:550) [MinecraftServer.class:?]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131-1-redhat]


Here's the repo:
https://github.com/Yuudaari/soulus

Am I doing something obviously wrong? I don't even know where to begin on a bug like this. Any tips for debugging things like this would be appreciated as well.

Link to comment
Share on other sites

What I got from your comment was that I need to remove all imports of SideOnly(Client) classes from classes running on the server side, correct? That would mean that I have to have two versions of each item that has a custom tooltip via overriding addInformation, because that method requires importing ITooltipFlag, which is SideOnly(Client)

Did I misunderstand something or do I really have to do this? That seems like so much bloat

Link to comment
Share on other sites

Stuff that is client side annotated has no meaning on the server. You can use sided annotation on specific fields and methods in your class. So if you have methods that reference client-side stuff you can annotate that method.  So just put sided annotation on your registerModels() method and anything that calls it.

Edited by jabelar
  • Like 1

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

I was able to resolve this initial issue thanks to your guys' help, but it's come up again for a weirder class, my NBTHelper utility https://github.com/Yuudaari/soulus/blob/master/src/main/java/yuudaari/soulus/common/util/NBTHelper.java

Can you guys see anything here that's client side only? I sure can't... I've gotta be doing something stupid, right?

For reference, here's the error:
 

java.lang.NoClassDefFoundError: yuudaari/soulus/common/util/NBTHelper
  at yuudaari.soulus.common.block.Summoner.SummonerTileEntity.writeToNBT(SummonerTileEntity.java:385) ~[SummonerTileEntity.class:?]
      at net.minecraft.world.chunk.storage.AnvilChunkLoader.writeChunkToNBT(AnvilChunkLoader.java:412) ~[AnvilChunkLoader.class:?]
   at net.minecraft.world.chunk.storage.AnvilChunkLoader.saveChunk(AnvilChunkLoader.java:183) ~[AnvilChunkLoader.class:?]
 at net.minecraft.world.gen.ChunkProviderServer.saveChunkData(ChunkProviderServer.java:214) ~[ChunkProviderServer.class:?]
      at net.minecraft.world.gen.ChunkProviderServer.saveChunks(ChunkProviderServer.java:242) ~[ChunkProviderServer.class:?]
 at net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:1060) ~[WorldServer.class:?]
 at net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:468) ~[MinecraftServer.class:?]
     at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:509) ~[MinecraftServer.class:?]
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:643) [MinecraftServer.class:?]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131-1-redhat]

 

Edited by Aarilight
Link to comment
Share on other sites

Is this code yours originally, or are you contributing to someone else's code? I'm asking because the code is fairly complex and seems to be fully implemented, yet errors like this are sort of fundamental so it is surprising you're finding this out now. If this is your own code, then I just want to pass on advice to say that it is important when doing a big mod to test every bit at a time to make sure it is working well before continuing to add code, otherwise you end up with this sort of thing (where you have tons of code but weird, fundamental bugs). 

 

In particular, the NBT stuff is a bit convoluted. I understand sometimes it is nice to encapsulate things with helpers, but in this case it is instantiating a builder that gets associated to a compound and redirecting almost everything you might want to do with NBT through methods that access that compound. Not sure that complexity is really necessary or worth it.

 

Anyway, it is true that there isn't anything obvious that would be related to sided issues. So maybe it is related to some other reason the class wouldn't be found. Like is there something wrong with the package or class path? 

  • Like 1

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Yes, I've written 99% of this myself, on and off for the past year or so. I'm a fulltime developer, but Java is probably my least favourite language, so my main deficiencies are with not being a Java expert or knowing all of the little intricacies with the Minecraft and Forge APIs.

I honestly don't even know how to debug issues like this, to be honest. The error isn't really helpful at all. I'm not sure what issues could lie in a package, and the class is for sure in the jar, so... I feel so helpless haha

Also, I had never tested with runServer because I mistakenly assumed that Open to LAN would be using most of the same code, (yea, it does, obviously, but all the client code is there still because it's still being run in a client). The past day has made me feel the stupidest I've ever felt... lol

Edited by Aarilight
Link to comment
Share on other sites

1 hour ago, Aarilight said:

Also, I had never tested with runServer because I mistakenly assumed that Open to LAN would be using most of the same code, (yea, it does, obviously, but all the client code is there still because it's still being run in a client). The past day has made me feel the stupidest I've ever felt... lol

 

Yeah, it took me a while to realize that a modder should pretty much always test with a dedicated server as the client run configuration hides all this sided stuff, so that makes sense while this was lurking while you got things well developed...

 

So if it is only happening when running as server I guess it probably is related to sided class loading.

 

In terms of debugging it, sometimes errors are thrown in a way that doesn't correctly identify the root cause. Like maybe the calling class has an issue.

 

But I have some suggestions. First of all, it seems to be having trouble on the line where it instantiates a new NBTHelper. So why not try commenting out everything except the constructor in the NBTHelper class and see if it fixes the issue. If it does, then add the methods back one at a time until a problem occurs. If the issue isn't fixed by minimizing the code in the class, then that would be odd but you could try looking at class loader inspection. Others on this forum might be more familiar with the class loader, but generally you might be able to inspect it using standard techniques in Eclipse: https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.mat.ui.help%2Ftasks%2Fanalyzingclassloader.html

 

In general the error means that the class is not loaded (into memory) for the JVM (in this case the server JVM). I think you can also set the run configuration vm to be more verbose in the console and perhaps more class loading info might show up.

 

Edited by jabelar
  • Like 1

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

I commented every single thing out of the NBTHelper and nothing has changed. How would I go about making the JVM more verbose? Is there an option with gradlew or something? Since I test via  gradlew runServer. I don't use Eclipse for development, but if I can't figure this out altogether I'll get it to try to fix this bug. Thanks for the tips!

[edit]
It for sure is an issue with the NBTHelper class because after removing all references to it, the error doesn't happen anymore. I don't understand why just this one class has NoClassDefFoundErrors. Weirdest thing ever. Does anyone have any ideas?

Edited by Aarilight
Link to comment
Share on other sites

I went from new NBTHelper().nbt (which returns an NBTTagCompound) to new NBTTagCompound() and that made it work, before that it did not work. NBTHelper was completely commented out except for its constructor and the nbt field. I had previously commented out all other lines that used NBTHelper methods and since that didn't fix it, that's when I switched to commenting out the use of NBTHelper altogether.

After removing all of the references to NBTHelper and extracting the methods I was using in it to each place that called them, it works. I'm not a fan of the change because it adds a lot more lines to each place that used to call it, but it working is better than a crash any day.

Edited by Aarilight
Link to comment
Share on other sites

I use VSCode for Java development because I like pain.

(Kidding, it's because I use VSCode for everything else and I really dislike having to configure more than one IDE, when I already know everything about this one and have tweaked it do literally everything I want... it does lack some basic features of Eclipse and IntelliJ but it gets better over time. Also, I'm not really a fan of things that Just Work ™, I'd rather know exactly how a Java/modding workspace needs to be set up to make it work)

Link to comment
Share on other sites

Is there something that I don't understand about how classes within classes work? I found another instance of NoClassDefFoundError
 

java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: yuudaari/soulus/common/block/summoner/Summoner$1
	at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_131-1-redhat]
	at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_131-1-redhat]
	at net.minecraft.util.Util.runTask(Util.java:54) [Util.class:?]
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:796) [MinecraftServer.class:?]
	at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(DedicatedServer.java:414) [DedicatedServer.class:?]
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:741) [MinecraftServer.class:?]
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:590) [MinecraftServer.class:?]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131-1-redhat]
Caused by: java.lang.NoClassDefFoundError: yuudaari/soulus/common/block/summoner/Summoner$1
	at yuudaari.soulus.common.block.summoner.Summoner.onBlockActivated(Summoner.java:263) ~[Summoner.class:?]
	at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:472) ~[PlayerInteractionManager.class:?]
	at net.minecraft.network.NetHandlerPlayServer.processTryUseItemOnBlock(NetHandlerPlayServer.java:767) ~[NetHandlerPlayServer.class:?]
	at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:68) ~[CPacketPlayerTryUseItemOnBlock.class:?]
	at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:13) ~[CPacketPlayerTryUseItemOnBlock.class:?]
	at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_131-1-redhat]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_131-1-redhat]
	at net.minecraft.util.Util.runTask(Util.java:53) ~[Util.class:?]


This is the file in question (there have been a couple local edits since then, but not affecting this method):
https://github.com/Yuudaari/soulus/blob/master/src/main/java/yuudaari/soulus/common/block/Summoner/Summoner.java

Summoner$1 would be the Upgrades class, right? Why would that not exist? I feel like there's some basic concept here about classes and sides that I'm still not getting, maybe.

Edited by Aarilight
Link to comment
Share on other sites

Oh, thanks! That is something I totally didn't know and probably wouldn't have figured out. 

Why would removing the switch fix it? Cause just for the heck of it I tried removing the switch (and using an if/else statement that does the same thing instead) and it worked fine. 

Link to comment
Share on other sites

I think I finally fixed all of the crashes. Thank you guys for your help. I still don't understand why a couple of them happened but nevertheless I was able to fix them. I do have one more issue (only visual, tho) but I'm going to make a separate thread about it. Thanks again, this makes it so I have a working release, hah

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.