-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Description
Exceptions thrown from kotlinx.coroutines.rx3.rxSingle.await()
that have a constructor with a Throwable
param are being wrapped in a new instance of the same class. This is only happening when code is executed from within a @org.junit.jupiter.api.Test
. The expected behaviour, I assume, is for the thrown exception to be delivered as-is, as it is done when the code is executed from main()
.
Steps to reproduce
Expected/Actual output:
org.example.ExceptionWithThrowableParam: java.lang.Exception
java.lang.Exception
Main.kt
package org.example
import kotlinx.coroutines.rx3.await
import kotlinx.coroutines.rx3.rxSingle
suspend fun main() {
repro()
}
suspend fun repro() {
try {
rxSingle {
throw ExceptionWithThrowableParam(Exception())
}.await()
} catch (e: Exception) {
println(e) // org.example.ExceptionWithThrowableParam: java.lang.Exception
println(e.cause) // java.lang.Exception
}
}
class ExceptionWithThrowableParam(inner: Throwable) : Exception(inner) // this works in `main()`, but fails in `test()`
//class ExceptionWithThrowableParam(inner: Exception) : Exception(inner) // this works fine in `main()` and `test()`
Actual output when run within @Test
:
org.example.ExceptionWithThrowableParam: org.example.ExceptionWithThrowableParam: java.lang.Exception
org.example.ExceptionWithThrowableParam: java.lang.Exception
Test.kt
import kotlinx.coroutines.test.runTest
import org.example.repro
import kotlin.test.Test
class Test {
@Test
fun test() = runTest {
repro()
}
}
build.gradle.kts
plugins {
kotlin("jvm") version "2.2.20"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-rx3:1.10.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.10.2")
implementation("io.reactivex.rxjava3:rxjava:3.1.1")
testImplementation(kotlin("test"))
}
tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(21)
}
Context
JUnit4 / 5