asusoda / Corundum

This is a new plugin-based server-side modding A.P.I. for Minecraft. [WIP]
MIT License
7 stars 1 forks source link

Another big issue... And it's Log4J again #17

Closed Variadicism-zz closed 9 years ago

Variadicism-zz commented 9 years ago

So, I tried compiling and running our current code and found out that it doesn't work. Log4J throws a NullPointerException when the Corundum Hub tries to start the server. I tracked the bug via stack trace and found that it looks like there's no entry in a pluginTypeMap inside a PatternParser class in org.apache.logging.log4j.core.impl.patternfor a plugin type that they seem to assume was there, causing a call to getPlugins() to return null and cause the NPE when another part of the code calls values() on the null plugins map. (I think that package is right, but it's off the top of my head, so it might not be exactly right.) I'll put the stack trace down here tomorrow when I have access to Wi-Fi for my laptop. (I'm posting this from my phone.)

I have no idea what's causing it. I don't think we changed anything in the ClassLoaders or starting algorithms that could do this, but even so, I looked at an old sample of Corundum's code and tried changing certain parts back to the way they were before. Nothing has worked so far.

Some of the changes I've investigated as possible causes are as follows: 1) the merging of Corundum and CorundumServer into one class. I thought maybe starting right in the CorundumServer class instead of starting from a Corundum class and moving into a CorundumServer class might change the initialization order of some fields or methods. I tried remaking a Corundum class and moving some initializer stuff and the primary start method used by the Hub into it. That didn't seem to help. 2) the encapsulation of a CorundumServer into a CorundumServerThread. I tried basically copying the code from the CorundumServerThread constructor and run() method into the CorundumHub main() method directly. That didn't seem to have any effect.

This is why I hate Log4J. Every time I have the displeasure to work with it, it breaks inexplicably whenever you try to change anything big like your project directory or anything to do with ClassLoaders.

So, we only really have two major issues right now: the logging not appearing in the default Minecraft GUI and this issue, both of which are caused by Log4J and I am at a loss on how to fix either. Log4J's code is confusing and their documentation is not all that helpful.

Any ideas or tests or attempts to fix this would be appreciated.

Variadicism-zz commented 9 years ago

Here's the full output:

Loading the Minecraft server jar...
loaded /home/connor/Minecraft/Corundum testing/minecraft_server.jar
Loading the Corundum server jar...
loaded /home/connor/Minecraft/Corundum testing/Corundum.jar
Running Corundum server...
Something went wrong in initializing the Corundum server!
java.lang.ExceptionInInitializerError
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:340)
    at org.corundummc.hub.CorundumThread.run(CorundumThread.java:171)
Caused by: java.lang.NullPointerException
    at org.apache.logging.log4j.core.pattern.PatternParser.<init>(PatternParser.java:120)
    at org.apache.logging.log4j.core.pattern.PatternParser.<init>(PatternParser.java:102)
    at org.apache.logging.log4j.core.layout.PatternLayout.createPatternParser(PatternLayout.java:183)
    at org.apache.logging.log4j.core.layout.PatternLayout.<init>(PatternLayout.java:115)
    at org.apache.logging.log4j.core.layout.PatternLayout.createLayout(PatternLayout.java:219)
    at org.apache.logging.log4j.core.config.DefaultConfiguration.<init>(DefaultConfiguration.java:51)
    at org.apache.logging.log4j.core.LoggerContext.<init>(LoggerContext.java:63)
    at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:217)
    at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:145)
    at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:81)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:83)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:34)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:387)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:322)
    at net.minecraft.server.MinecraftServer.<clinit>(SourceFile:49)
    ... 3 more

The error occurs when Java attempts to resolve the Corundum main class, which normally means resolving CorundumServer.class when it loads it in the main() method of the Corundum Hub at a line like this:

Class<?> main_class = Class.forName("org.corundummc.CorundumServer", true, Corundum_loader);
Variadicism-zz commented 9 years ago

Oh, phew! I found it! This is what the issue was:

As it stands now, all the resources from the minecraft_server.jar need to be copied into the Corundum Hub.jar at build time because of ClassLoader weirdness with resource loading; I'm still working on a fix for this.

Anyway, I've set up my compile script for the Corundum Hub to run the compilation through MCP, then copy all the class files into a folder with all the Minecraft resources I already had extracted, then put all the stuff in that folder into a jar. However, I make it delete the old Corundum compiled code first to avoid adding useless classes in there that could cause errors on loading and take up space, but since we recently changed the main package name from "Corundum" to "org.corundummc", the script was deleting the whole org folder, which included the old Corundum Hub code but also one resource file in the org.apache package (since they're both in the "org" folder).

In short, my build script was deleting a plugin dat file that Log4J uses to load its plugins. That's why it was throwing that error.

There are still a couple more unrelated errors with the new setup I need to clean up. That shouldn't take long, but I'll have to do it later seeing as how I have to go to work now. It's nothing I don't know how to fix.

shanedublin commented 9 years ago

Can you guys take me off your email list? On Nov 17, 2014 10:33 AM, "REALDrummer" notifications@github.com wrote:

Closed #17 https://github.com/asusoda/Corundum/issues/17.

— Reply to this email directly or view it on GitHub https://github.com/asusoda/Corundum/issues/17#event-194349682.

Variadicism-zz commented 9 years ago

The e-mails come from GitHub; I think to stop receiving them, you press the "Unwatch" button near the top-right of any page concerning this repo and select "Ignore" from that drop-down menu.