-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed as not planned
Description
Describe the bug
JavaScript allows to throw strings, but it leads to ClassCastException is thrown in kotlinx-coroutines-core
Looks createCauseException is the root cause of ClassCastException , String is not Throwable so it is trying to be cast to ParentJob
kotlinx.coroutines/kotlinx-coroutines-core/common/src/JobSupport.kt
Lines 748 to 752 in 6c6df2b
| // cause is Throwable or ParentJob when cancelChild was invoked | |
| private fun createCauseException(cause: Any?): Throwable = when (cause) { | |
| is Throwable? -> cause ?: defaultCancellationException() | |
| else -> (cause as ParentJob).getChildJobCancellationCause() | |
| } |
Provide a Reproducer
class TestClient2 {
@Test
fun testThrowString() = runTest {
val job = launch {
println("throwing a JS string")
throw IllegalStateException("EMPTY") //In JS everything can be thrown, even a String!
println("not executed....")
}
println("waiting for job")
job.join()
}
}