From 49684820e3f1ba81fb3b7b4ed1d9a09a1c686446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20R=C3=B6ssler?= Date: Thu, 18 Nov 2021 13:59:36 +0100 Subject: [PATCH] Update the KotlinUnsafeCastOperatorFilter for Kotlin 1.6.0 --- .../analysis/filter/KotlinUnsafeCastOperatorFilter.java | 6 ++++++ 1 file changed, 6 insertions(+) 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..16813f9f84 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,12 @@ public void match(final String exceptionType, } cursor = start; final JumpInsnNode jumpInsnNode = (JumpInsnNode) cursor; + if (cursor.getNext().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. + cursor = cursor.getNext(); + } nextIsType(Opcodes.NEW, exceptionType); nextIs(Opcodes.DUP); nextIs(Opcodes.LDC);