From cc4f5f11cda09fc76aa4e67b73ec4b1df13dbb48 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Thu, 2 Feb 2017 15:39:35 +0000 Subject: [PATCH] Fix NPE when no array-access opcode is found near to field. Closes #166 --- .../mixin/injection/invoke/RedirectInjector.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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 fa017ee2..dc984469 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 @@ -356,7 +356,7 @@ public class RedirectInjector extends InvokeInjector { private void injectAtGetArray(Target target, FieldInsnNode fieldNode, AbstractInsnNode varNode, Type ownerType, Type fieldType) { String handlerDesc = Bytecode.generateDescriptor(this.returnType, (Object[])RedirectInjector.getArrayArgs(fieldType)); boolean withArgs = this.checkDescriptor(handlerDesc, target, "array getter"); - this.injectArrayRedirect(target, fieldNode, varNode, withArgs); + this.injectArrayRedirect(target, fieldNode, varNode, withArgs, "array getter"); } /** @@ -365,7 +365,7 @@ public class RedirectInjector extends InvokeInjector { private void injectAtSetArray(Target target, FieldInsnNode fieldNode, AbstractInsnNode varNode, Type ownerType, Type fieldType) { String handlerDesc = Bytecode.generateDescriptor(null, (Object[])RedirectInjector.getArrayArgs(fieldType, fieldType.getElementType())); boolean withArgs = this.checkDescriptor(handlerDesc, target, "array setter"); - this.injectArrayRedirect(target, fieldNode, varNode, withArgs); + this.injectArrayRedirect(target, fieldNode, varNode, withArgs, "array setter"); } /** @@ -379,8 +379,15 @@ public class RedirectInjector extends InvokeInjector { * @param varNode array access node * @param withArgs true if the descriptor includes captured arguments from * the target method signature + * @param type description of access type for use in error messages */ - public void injectArrayRedirect(Target target, FieldInsnNode fieldNode, AbstractInsnNode varNode, boolean withArgs) { + public void injectArrayRedirect(Target target, FieldInsnNode fieldNode, AbstractInsnNode varNode, boolean withArgs, String type) { + if (varNode == null) { + String advice = ""; + throw new InvalidInjectionException(this.info, "Array element " + this.annotationType + " on " + this + " could not locate a matching " + + type + " instruction in " + target + ". " + advice); + } + if (!this.isStatic) { target.insns.insertBefore(fieldNode, new VarInsnNode(Opcodes.ALOAD, 0)); target.addToStack(1);