Add missing staticness check to ModifyConstant Injector

This commit is contained in:
Mumfrey committed 2017-07-07 16:39:38 +01:00
1 parent 5abbd50b28
commit ec6d8f6521
3 files changed
+12 -8

No files matched your search

@@ -72,18 +72,22 @@ public abstract class InvokeInjector extends Injector {
* @param target target
*/
protected void checkTarget(Target target) {
this.checkTargetModifiers(target);
this.checkTargetModifiers(target, true);
}
/**
* Check that the <tt>static</tt> modifier of the target method matches the
* handler
*
* @param target
* @param target Target to check
* @param exactMatch True if static must match, false to only check if an
* instance handler is targetting a static method
*/
protected final void checkTargetModifiers(Target target) {
if (target.isStatic != this.isStatic) {
protected final void checkTargetModifiers(Target target, boolean exactMatch) {
if (exactMatch && target.isStatic != this.isStatic) {
throw new InvalidInjectionException(this.info, "'static' modifier of handler method does not match target in " + this);
} else if (!exactMatch && !this.isStatic && target.isStatic) {
throw new InvalidInjectionException(this.info, "non-static callback method " + this + " targets a static method which is not supported");
}
}
@@ -110,7 +114,7 @@ public abstract class InvokeInjector extends Injector {
return;
}
}
this.checkTargetModifiers(target);
this.checkTargetModifiers(target, true);
}
/* (non-Javadoc)
@@ -56,9 +56,7 @@ public class ModifyArgsInjector extends InvokeInjector {
*/
@Override
protected void checkTarget(Target target) {
if (!this.isStatic && target.isStatic) {
throw new InvalidInjectionException(this.info, "non-static callback method " + this + " targets a static method which is not supported");
}
this.checkTargetModifiers(target, false);
}
@Override
@@ -67,11 +67,13 @@ public class ModifyConstantInjector extends RedirectInjector {
AbstractInsnNode targetNode = node.getCurrentTarget();
if (targetNode instanceof JumpInsnNode) {
this.checkTargetModifiers(target, false);
this.injectExpandedConstantModifier(target, (JumpInsnNode)targetNode);
return;
}
if (Bytecode.isConstant(targetNode)) {
this.checkTargetModifiers(target, false);
this.injectConstantModifier(target, targetNode);
return;
}