-
Notifications
You must be signed in to change notification settings - Fork 23
Add ParameterAnnotationFixer #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ParameterAnnotationFixer #3
Conversation
This fixes RuntimeVisibleParameterAnnotations and RuntimeInvisibleParameterAnnotations attributes to repair a case where ProGuard adds extra values for synthetic parameters (where the correct number of parameters is poorly defined). See MinecraftForge/ForgeGradle#472.
|
Cases that this doesn't handle:
|
ProGuard has been updated since the inception of this fix in ModCoderPack/MCInjector#3 and no longer has the original bug. Mojang also appears to be using newer versions of ProGuard where the bug is not present. The fixer is now properly programmed to change nothing if it doesn't detect the broken PG behavior. The fixer is now also optimized to use the visitor system instead of populating a ClassNode; it has been rewritten to do so.
ProGuard has been updated since the inception of this fix in ModCoderPack/MCInjector#3 and no longer has the original bug. Mojang also appears to be using newer versions of ProGuard where the bug is not present. The fixer is now properly programmed to change nothing if it doesn't detect the broken PG behavior. The fixer is now also optimized to use the visitor system instead of populating a ClassNode; it has been rewritten to do so.
This fixes
RuntimeVisibleParameterAnnotationsandRuntimeInvisibleParameterAnnotationsattributes to repair a case where ProGuard adds extra values for synthetic parameters (where the correct number of parameters is poorly defined). See MinecraftForge/ForgeGradle#472.This detects synthetic parameters by following the same logic the compiler uses to insert them. There are two places where such synthetic parameters are added:
Enums (for the name and ordinal), compiler source here and also noted by CFR here
Inner classes (for the synthetic parameter that references the outer class), compiler source here and also noted by CFR here. I exclude anonymous classes based off of this info in the compiler; it also appears that anonymous classes do not have info about the outer class so this is fine.
This check does depend on having accurate
InnerClassesinformation. This has been provided since some time in 1.8 (at the same time, we started getting classes with$in the name obfuscated for inner classes, which is how it should be), and as such is available in all versions that have annotations.While theoretically we could detect synthetic params in a much simpler manner by checking the
MethodParametersattribute, Minecraft does not include that attribute.Here is a diff of the resulting changes. There are two inner classes with constructors that have annotations on them:
SPacketPlayerListItem$AddPlayerDataandRenderGlobal$ContainerLocalRenderInformation(which was previously noticed in ModCoderPack/MCPBot-Issues#257). There are no enums with constructors that have annotations on them. This is the case for both Minecraft 1.12.2 (as shown in that diff) and 1.9.4 (only ran exceptor; determined by checking the output).