md-5 / SpecialSource

Automatic generator and renamer of jar obfuscation mappings.
Other
202 stars 51 forks source link

Issue when reobfuscating lambda methods #60

Closed ichttt closed 3 years ago

ichttt commented 3 years ago

(Originally opened as https://github.com/MinecraftForge/ForgeGradle/issues/716)

Using minecraft 1.16.2 with ForgeGradle 3

I've recently started using official names. However, there appears to be an issue somewhere in the reobf process when building a jar. This line causes issues: https://github.com/ichttt/SoundDeviceOptions/blob/8a6e49b8e6e9e1337585d23bc2453db5a6d2006b/src/main/java/ichttt/mods/sounddeviceoptions/client/gui/GuiSound.java#L47 as it compiled to the following (decompiled code using CFR of the reobfed jar):

        this.func_230480_a_((Widget)new Button(this.field_230708_k_ / 2 - 100, this.field_230709_l_ / 6 + 156, 200, 20, (ITextComponent)new TranslationTextComponent("sounddeviceoptions.output", new Object[]{SDOConfig.friendlyActiveSoundDevice()}), (Button.IPressable)LambdaMetafactory.metafactory(null, null, null, (Lnet/minecraft/client/gui/widget/button/Button;)V, func_213105_b(net.minecraft.client.gui.widget.button.Button ), (Lnet/minecraft/client/gui/widget/button/Button;)V)((GuiSound)this)));

Notice that the Metafactory references the func_213105_b method, which is a private synthetic lambda method of the super class (OptionsSoundsScreen), instead of the lambda$init$0 method, which is the correct private synthetic lamda method of my GuiSound class. This causes the following stacktrace when running the game from the launcher:

java.lang.IllegalAccessError: tried to access method net.minecraft.client.gui.screen.OptionsSoundsScreen.func_213105_b(Lnet/minecraft/client/gui/widget/button/Button;)V from class ichttt.mods.sounddeviceoptions.client.gui.GuiSound
    at java.lang.invoke.MethodHandleNatives.resolve(Native Method) ~[?:1.8.0_51] {}
    at java.lang.invoke.MemberName$Factory.resolve(MemberName.java:962) ~[?:1.8.0_51] {}
    at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:987) ~[?:1.8.0_51] {}
    at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:1390) ~[?:1.8.0_51] {}
    at java.lang.invoke.MethodHandles$Lookup.linkMethodHandleConstant(MethodHandles.java:1746) ~[?:1.8.0_51] {}
    at java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(MethodHandleNatives.java:477) ~[?:1.8.0_51] {}
    at ichttt.mods.sounddeviceoptions.client.gui.GuiSound.func_231160_c_(GuiSound.java:47) ~[?:1.4.1] {re:classloading}
    at net.minecraft.client.gui.screen.Screen.func_231158_b_(Screen.java:323) ~[?:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.func_147108_a(Minecraft.java:829) ~[?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}

Here are the classes (from the jar after reobf and when compiling using javac): Classes.zip You should be able to reproduce the issue by forking https://github.com/ichttt/SoundDeviceOptions and running gradlew build

md-5 commented 3 years ago

Would be helpful if you could narrow it down to an independent test case not dependent on the MC mappings or your mod code

ichttt commented 3 years ago

See https://github.com/ichttt/SpecialSourceIssue60Reproducer I've create a small class set to reproduce the issue without any mc or mod code. Read the readme for how I set this up

md-5 commented 3 years ago

Fixed in ac2c4663cbcf430ecd2ad0878771f58e053b8f51

Thanks