Skip to content

Filter Kotlin 2.5.0 throwNoWhenBranchMatchedException bytecode - #2249

Open
arimu1 wants to merge 1 commit into
jacoco:masterfrom
arimu1:issue-2216-kotlin-when-filter-2.5
Open

Filter Kotlin 2.5.0 throwNoWhenBranchMatchedException bytecode#2249
arimu1 wants to merge 1 commit into
jacoco:masterfrom
arimu1:issue-2216-kotlin-when-filter-2.5

Conversation

@arimu1

@arimu1 arimu1 commented Aug 7, 2026

Copy link
Copy Markdown

Description

Kotlin 2.5.0 changed the bytecode generated for the implicit default branch of exhaustive when expressions/statements: instead of constructing NoWhenBranchMatchedException directly, the compiler loads the subject and calls kotlin.internal.throwNoWhenBranchMatchedException, then throws KotlinNothingValueException (see JetBrains/kotlin@d3fba8a and JetBrains/kotlin@0562bdb).

This extends KotlinWhenFilter so it still recognizes and filters that implicit default branch, while keeping support for the pre-2.5.0 pattern.

Related issue

Fixes #2216

How to test

export JAVA_HOME=$(/usr/libexec/java_home -v 21)
mvn -pl org.jacoco.core,org.jacoco.report,org.jacoco.agent.rt,org.jacoco.agent -am install -DskipTests
mvn -pl org.jacoco.core.test test -Dtest=KotlinWhenFilterTest

All 9 KotlinWhenFilterTest cases pass (existing patterns + three new Kotlin 2.5.0 cases for implicit else, implicit default switch, and nullable enum without else).

Kotlin 2.5.0 generates an exhaustive when default branch via
throwNoWhenBranchMatchedException + KotlinNothingValueException
instead of constructing NoWhenBranchMatchedException directly.
Extend KotlinWhenFilter to recognize both patterns.

Fixes jacoco#2216
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update KotlinWhenFilter for Kotlin 2.5.0

1 participant