diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/build/intercept/javafeatures/ImplicitNullCheckFilter.java b/pitest-entry/src/main/java/org/pitest/mutationtest/build/intercept/javafeatures/ImplicitNullCheckFilter.java index bcd4fb0c2..da8974ab1 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/build/intercept/javafeatures/ImplicitNullCheckFilter.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/build/intercept/javafeatures/ImplicitNullCheckFilter.java @@ -12,7 +12,6 @@ import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.LabelNode; -import org.objectweb.asm.tree.MethodInsnNode; import org.pitest.bytecode.analysis.ClassTree; import org.pitest.bytecode.analysis.MethodTree; import org.pitest.classinfo.ClassName; @@ -23,6 +22,7 @@ import org.pitest.mutationtest.engine.Mutater; import org.pitest.mutationtest.engine.MutationDetails; import org.pitest.sequence.Context; +import org.pitest.sequence.Match; import org.pitest.sequence.QueryParams; import org.pitest.sequence.QueryStart; import org.pitest.sequence.SequenceMatcher; @@ -36,7 +36,7 @@ public class ImplicitNullCheckFilter implements MutationInterceptor { static final SequenceMatcher GET_CLASS_NULL_CHECK = QueryStart .any(AbstractInsnNode.class) - .then(methodCallTo(ClassName.fromClass(Object.class), "getClass").and(isInstruction(MUTATED_INSTRUCTION.read()))) + .then(aGetClassCall().and(isInstruction(MUTATED_INSTRUCTION.read()))) .then(POP) // immediate discard .then(isA(LabelNode.class).negate()) // use presence of a label to indicate this was a programmer call to getClass .zeroOrMore(QueryStart.match(anyInstruction())) @@ -45,6 +45,10 @@ public class ImplicitNullCheckFilter implements MutationInterceptor { .withDebug(DEBUG) ); + private static Match aGetClassCall() { + return methodCallTo(ClassName.fromClass(Object.class), "getClass"); + } + private ClassTree currentClass; @@ -73,10 +77,11 @@ private Predicate isAnImplicitNullCheck() { final AbstractInsnNode mutatedInstruction = method.instruction(instruction); // performance hack - if (!(mutatedInstruction instanceof MethodInsnNode)) { - return false; + if (!aGetClassCall().asPredicate().test(mutatedInstruction)) { + return false; } + Context context = Context.start(DEBUG); context = context.store(MUTATED_INSTRUCTION.write(), mutatedInstruction); return GET_CLASS_NULL_CHECK.matches(method.instructions(), context);