From 5abbd50b287b551c50a8fa0c469e7ffa5acf3800 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Fri, 7 Jul 2017 11:52:18 +0100 Subject: [PATCH] Fix broken logic for staticness checks on injector handlers, fixes #193 --- .../injection/invoke/InvokeInjector.java | 32 +++++++++++++------ .../injection/invoke/RedirectInjector.java | 2 -- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java index 926b8d50..1c240f2b 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java @@ -72,8 +72,18 @@ public abstract class InvokeInjector extends Injector { * @param target target */ protected void checkTarget(Target target) { + this.checkTargetModifiers(target); + } + + /** + * Check that the static modifier of the target method matches the + * handler + * + * @param target + */ + protected final void checkTargetModifiers(Target target) { if (target.isStatic != this.isStatic) { - throw new InvalidInjectionException(this.info, "'static' modifier of callback method does not match target in " + this); + throw new InvalidInjectionException(this.info, "'static' modifier of handler method does not match target in " + this); } } @@ -89,16 +99,18 @@ public abstract class InvokeInjector extends Injector { * @param node Injection location */ protected void checkTargetForNode(Target target, InjectionNode node) { - if (!target.isCtor) { - return; - } - - MethodInsnNode superCall = target.findSuperInitNode(); - int superCallIndex = target.indexOf(superCall); - int targetIndex = target.indexOf(node.getCurrentTarget()); - if (targetIndex <= superCallIndex && !this.isStatic) { - throw new InvalidInjectionException(this.info, "Pre-super " + this.annotationType + " invocation must be static in " + this); + if (target.isCtor) { + MethodInsnNode superCall = target.findSuperInitNode(); + int superCallIndex = target.indexOf(superCall); + int targetIndex = target.indexOf(node.getCurrentTarget()); + if (targetIndex <= superCallIndex) { + if (!this.isStatic) { + throw new InvalidInjectionException(this.info, "Pre-super " + this.annotationType + " invocation must be static in " + this); + } + return; + } } + this.checkTargetModifiers(target); } /* (non-Javadoc) diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/RedirectInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/RedirectInjector.java index 9fb6e94f..35436c90 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/RedirectInjector.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/RedirectInjector.java @@ -231,14 +231,12 @@ public class RedirectInjector extends InvokeInjector { if (node.getCurrentTarget() instanceof MethodInsnNode) { this.checkTargetForNode(target, node); - super.checkTarget(target); this.injectAtInvoke(target, node); return; } if (node.getCurrentTarget() instanceof FieldInsnNode) { this.checkTargetForNode(target, node); - super.checkTarget(target); this.injectAtFieldAccess(target, node); return; }