diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinUnsafeCastOperatorFilter.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinUnsafeCastOperatorFilter.java index 82522a8ac9..7c373e4898 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinUnsafeCastOperatorFilter.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinUnsafeCastOperatorFilter.java @@ -46,6 +46,13 @@ public void match(final String exceptionType, } cursor = start; final JumpInsnNode jumpInsnNode = (JumpInsnNode) cursor; + AbstractInsnNode optionalPop = cursor.getNext(); + if (optionalPop != null && optionalPop.getOpcode() == Opcodes.POP) { + // Kotlin 1.6.0 DUPs the variable that's being casted and POPs it here, previous versions instead load + // the variable twice, once before IFNONNULL, and once before CHECKCAST. To be compatible with both, we + // can just skip the POP. + next(); + } nextIsType(Opcodes.NEW, exceptionType); nextIs(Opcodes.DUP); nextIs(Opcodes.LDC);