diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/callback/CallbackInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/callback/CallbackInjector.java index 98f5ef86..e24bb9f5 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/callback/CallbackInjector.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/callback/CallbackInjector.java @@ -145,9 +145,12 @@ public class CallbackInjector extends Injector { this.locals = locals; this.localTypes = locals != null ? new Type[locals.length] : null; this.frameSize = ASMHelper.getFirstNonArgLocalIndex(target.arguments, !CallbackInjector.this.isStatic()); - List argNames = null; + List argNames = null; + + ASMHelper.printNode(this.node); if (locals != null) { + int baseArgIndex = CallbackInjector.this.isStatic() ? 0 : 1; argNames = new ArrayList(); for (int l = 0; l <= locals.length; l++) { if (l == this.frameSize) { @@ -155,7 +158,7 @@ public class CallbackInjector extends Injector { } if (l < locals.length && locals[l] != null) { this.localTypes[l] = Type.getType(locals[l].desc); - if (l > 0) { + if (l >= baseArgIndex) { argNames.add(locals[l].name); } } @@ -323,6 +326,17 @@ public class CallbackInjector extends Injector { } } } else { + // Check whether user is just using the wrong CallbackInfo type + String returnableSig = this.methodNode.desc.replace( + "Lorg/spongepowered/asm/mixin/injection/callback/CallbackInfo;", + "Lorg/spongepowered/asm/mixin/injection/callback/CallbackInfoReturnable;"); + + if (callback.getDescriptor().equals(returnableSig)) { + // Switching out CallbackInfo for CallbackInfoReturnable + // worked, so notify the user that they done derped + throw new InvalidInjectionException(this.info, "Invalid descriptor on callback: CallbackInfoReturnable is required!"); + } + throw new InvalidInjectionException(this.info, "Invalid descriptor on callback: expected " + callback.getDescriptor() + " but found " + this.methodNode.desc); } diff --git a/src/main/java/org/spongepowered/asm/util/ASMHelper.java b/src/main/java/org/spongepowered/asm/util/ASMHelper.java index 521ddc49..92084a0f 100644 --- a/src/main/java/org/spongepowered/asm/util/ASMHelper.java +++ b/src/main/java/org/spongepowered/asm/util/ASMHelper.java @@ -360,7 +360,7 @@ public class ASMHelper { * @param node Node to print */ public static void printNode(AbstractInsnNode node) { - System.err.printf("%s ", node.getClass().getSimpleName()); + System.err.printf("%-14s ", node.getClass().getSimpleName().replace("Node", "")); if (node instanceof LabelNode) { System.err.printf("[%s]", ((LabelNode)node).getLabel()); } else if (node instanceof JumpInsnNode) { diff --git a/src/main/java/org/spongepowered/asm/util/Locals.java b/src/main/java/org/spongepowered/asm/util/Locals.java index dd105118..b0fdf0d1 100644 --- a/src/main/java/org/spongepowered/asm/util/Locals.java +++ b/src/main/java/org/spongepowered/asm/util/Locals.java @@ -190,6 +190,13 @@ public class Locals { break; } } + + // Null out any "unknown" locals + for (int l = 0; l < frame.length; l++) { + if (frame[l] != null && frame[l].desc == null) { + frame[l] = null; + } + } return frame; } @@ -317,8 +324,12 @@ public class Locals { } if (label == null) { - label = new LabelNode(); - labels[i] = label; + AbstractInsnNode existingLabel = method.instructions.get(i); + if (existingLabel instanceof LabelNode) { + label = (LabelNode) existingLabel; + } else { + labels[i] = label = new LabelNode(); + } } if (local == null && locals[j] != null) { diff --git a/src/main/java/org/spongepowered/asm/util/SignaturePrinter.java b/src/main/java/org/spongepowered/asm/util/SignaturePrinter.java index 87f22cac..2a4faeb1 100644 --- a/src/main/java/org/spongepowered/asm/util/SignaturePrinter.java +++ b/src/main/java/org/spongepowered/asm/util/SignaturePrinter.java @@ -118,6 +118,10 @@ public class SignaturePrinter { this.returnType = returnType; this.argTypes = argTypes; this.argNames = argNames; + if (this.argTypes.length > this.argNames.length) { + throw new IllegalArgumentException(String.format("Types array length must not exceed names array length! (names=%d, types=%d)", + this.argNames.length, this.argTypes.length)); + } } public String getReturnType() { @@ -172,8 +176,13 @@ public class SignaturePrinter { sb.append(' '); } } - String name = typesOnly ? null : Strings.isNullOrEmpty(this.argNames[var]) ? "unnamed" + var : this.argNames[var]; - this.appendType(sb, this.argTypes[var], name); + try { + String name = typesOnly ? null : Strings.isNullOrEmpty(this.argNames[var]) ? "unnamed" + var : this.argNames[var]; + this.appendType(sb, this.argTypes[var], name); + } catch (Exception ex) { + System.err.printf("\n\n>>> argTypes=%d, argNames=%d\n\n", this.argTypes.length, this.argNames.length); + throw new RuntimeException(ex); + } } return sb.append(")"); }