md-5 / SpecialSource

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

SourceFile attribute is not remapped #65

Open jpenilla opened 3 years ago

jpenilla commented 3 years ago

When compiling against Spigot's Mojang-mapped jar, I was getting tons of warnings about auxiliary classes:

/home/runner/work/special-gradle/special-gradle/test-plugin/src/main/java/xyz/jpenilla/specialgradle/testplugin/TestPlugin.java:27: warning: auxiliary class EntityArgument in ArgumentEntity.java should not be accessed from outside its own source file
import net.minecraft.commands.arguments.EntityArgument;
                                       ^
/home/runner/work/special-gradle/special-gradle/test-plugin/src/main/java/xyz/jpenilla/specialgradle/testplugin/TestPlugin.java:30: warning: auxiliary class Component in IChatBaseComponent.java should not be accessed from outside its own source file
import net.minecraft.network.chat.Component;
                                 ^
/home/runner/work/special-gradle/special-gradle/test-plugin/src/main/java/xyz/jpenilla/specialgradle/testplugin/TestPlugin.java:33: warning: auxiliary class ServerPlayer in EntityPlayer.java should not be accessed from outside its own source file
import net.minecraft.server.level.ServerPlayer;
                                 ^
/home/runner/work/special-gradle/special-gradle/test-plugin/src/main/java/xyz/jpenilla/specialgradle/testplugin/TestPlugin.java:42: warning: auxiliary class Commands in CommandDispatcher.java should not be accessed from outside its own source file
import static net.minecraft.commands.Commands.argument;
                                    ^
/home/runner/work/special-gradle/special-gradle/test-plugin/src/main/java/xyz/jpenilla/specialgradle/testplugin/TestPlugin.java:43: warning: auxiliary class Commands in CommandDispatcher.java should not be accessed from outside its own source file
import static net.minecraft.commands.Commands.literal;
                                    ^

... truncated, but there were many more similar warnings

Upon further inspection, I noticed that this is due to SpecialSource not remapping the SourceFile attribute at all.

This can bee seen by unzipping the Mojang-mapped Spigot jar from BuildTools, and running javap -v on any class file edited by Spigot or CraftBukkit, for example, ServerPlayer (EntityPlayer in Spigot names):

javap -v net/minecraft/server/level/ServerPlayer.class | grep SourceFile
  #3363 = Utf8               SourceFile
SourceFile: "EntityPlayer.java"
md-5 commented 3 years ago

I assume you have Xlint:all or something as I've never seen that warning. As a workaround you can use --kill-source to remove the SourceFile attribute or disable that specific warning in javac (-Xlint:-auxiliaryclass).

jpenilla commented 3 years ago

BuildTools is the one running SpecialSource in this case, otherwise I would have used --kill-source.

For my own projects I can disable the warning, sure, but I think it would be a better solution to either remap the attribute in SpecialSource, or to have BuildTools pass the argument to strip the attribute when building Spigot, this way Spigot jars won't have invalid metadata.