From 4c56961b9e0d6bfce98b44dda91bb82c3bd8223f Mon Sep 17 00:00:00 2001 From: cpw Date: Sat, 28 May 2016 18:05:24 -0400 Subject: [PATCH] Strip Optional from the class signature as well, since that's loaded by the TypeToken registry code and might cause a crash. --- .../asm/transformers/ModAPITransformer.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/minecraftforge/fml/common/asm/transformers/ModAPITransformer.java b/src/main/java/net/minecraftforge/fml/common/asm/transformers/ModAPITransformer.java index e76c1b7cb..531c38001 100644 --- a/src/main/java/net/minecraftforge/fml/common/asm/transformers/ModAPITransformer.java +++ b/src/main/java/net/minecraftforge/fml/common/asm/transformers/ModAPITransformer.java @@ -15,6 +15,8 @@ import net.minecraftforge.fml.relauncher.FMLRelaunchLog; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.signature.SignatureReader; +import org.objectweb.asm.signature.SignatureWriter; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.MethodNode; @@ -97,8 +99,16 @@ public class ModAPITransformer implements IClassTransformer { private void stripInterface(ClassNode classNode, String interfaceName, boolean stripRefs) { - String ifaceName = interfaceName.replace('.', '/'); + final String ifaceName = interfaceName.replace('.', '/'); boolean found = classNode.interfaces.remove(ifaceName); + if (found && classNode.signature != null) + { + SignatureReader sr = new SignatureReader(classNode.signature); + final RemovingSignatureWriter signatureWriter = new RemovingSignatureWriter(ifaceName); + sr.accept(signatureWriter); + classNode.signature = signatureWriter.toString(); + if (logDebugInfo) FMLRelaunchLog.finer("Optional removal - interface %s removed from type signature"); + } if (found && logDebugInfo) FMLRelaunchLog.finer("Optional removal - interface %s removed", interfaceName); if (!found && logDebugInfo) FMLRelaunchLog.finer("Optional removal - interface %s NOT removed - not found", interfaceName); @@ -157,4 +167,25 @@ public class ModAPITransformer implements IClassTransformer { } } + private static class RemovingSignatureWriter extends SignatureWriter + { + private final String ifaceName; + + RemovingSignatureWriter(String ifaceName) + { + this.ifaceName = ifaceName; + } + + @Override + public void visitClassType(String name) + { + if (name.equals(ifaceName)) { + super.visitClassType("java/lang/Object"); + } + else + { + super.visitClassType(name); + } + } + } }