Jump to content

1.12 Gradlew Build compiler switches around variables


Recommended Posts

Posted

As you saw from the title, when compiling my code, the compiler switches a variable around making the code crash when starting the game.

I'm first gonna say that I am not new to Java, I have used Java for 6 years and I know not everything but far more than the basics.

 

So currently me and a friend are making a mod for our own modpack, and it's going well. The mod has well over 20k lines and we already have 100k downloads. But just today as I was about to compile it and test it "on the production line" if you get what I mean, I noticed something I have never experienced before in my time of coding in Java. Basicly the compiler, switches around which variable I assign, meaning the code works fine when running in eclipse but when you run it after releasing it, it does not work.

So the code it occurs in is our Party Chat feature. It's basicly the main chat but moved to the right of the screen which only shows messages from the party chat. Also note here that this mod only works on a minecraft MMORPG server that most people should know about by now. We recently updated from 1.10.0 to 1.12.0, and today is the first time I myself tries it outside of eclipse after updating.

 

So about giving code. I'm currently modifying the vanilla code and adjust it to our liking, but something strange happened that didn't happen in the 1.10 version.

I have this code in the party chat, I'm creating my own Logger variable from GuiScreen, with the same name as the GuiScreen one. This has worked before and only became a problem when we updated to 1.12.

So the source looks like this:

public class GuiPartyChatbox extends GuiScreen implements ITabCompleter
{
    private static final Logger LOGGER = LogManager.getLogger();
    [...]

This works fine when running in eclipse, as we clearly state that our LOGGER variable is equal to LogManager.getLogger();

 

Now however, when I compile it, it changes which variable it assigns. How? Well as you know the compiler changes "static <type> <name> = <init>;" into "static <type> <name>;" and "static { <name> = <init>; }" and this is where the problem occurs

In GuiScreen, we have the same line at the top of the screen, which when obfuscated has the name "field_175287_a". So I kept digging to find a reason for the crash, until I decompiled the code using Cavaj Java Decompiler (very old decomp but it still works... sort of). What I found was that the code had changed from the one above, to this.

public class GuiPartyChatbox extends GuiScreen implements ITabCompleter
{
    private static final Logger LOGGER;

    [...]

    static 
    {
        field_175287_a = LogManager.getLogger();
    }
}

This means instead of initializing my LOGGER variable it tries to initialize the one in the super class, which in this case is obfuscated. This means that gradle obfuscate my variable because it has the same name as a variable in the super class, despite that class being set to private meaning I can't access that variable, making me crash with this crash report on startup:

Caused by: java.lang.IllegalAccessError: tried to access field net.minecraft.client.gui.GuiScreen.field_175287_a from class com.kirdow.enhancewynn.logic.gui.GuiPartyChatbox
	at com.kirdow.enhancewynn.logic.gui.GuiPartyChatbox.<clinit>(GuiPartyChatbox.java:353)

I'm not sure how to fix this other than renaming the variable but that to be honest doesn't seem to be the real option, as that's not really how it's meant to be, is it? So if I can't rename the variable for some reason, what choices do I have to fix this problem or is it just to wait for a fix by a new update (if there isn't one already)?

Posted
2 hours ago, Kirdow said:

I'm currently modifying the vanilla code and adjust it to our liking

What you are doing is not supported by Forge.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.