Skip to content

ClassCastException: class kotlinx.coroutines.test.TestCoroutineScheduler$timeSource$1 cannot be cast to class kotlin.time.TimeSource$WithComparableMarks #4429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
niqo01 opened this issue May 5, 2025 · 1 comment

Comments

@niqo01
Copy link

niqo01 commented May 5, 2025

Describe the bug

Using:
kotlin = "2.1.20"
coroutine = "1.10.2"

In my test class if I use runTest I get the error:

java.lang.ClassCastException: class kotlinx.coroutines.test.TestCoroutineScheduler$timeSource$1 cannot be cast to class kotlin.time.TimeSource$WithComparableMarks (kotlinx.coroutines.test.TestCoroutineScheduler$timeSource$1 and kotlin.time.TimeSource$WithComparableMarks are in unnamed module of loader 'app')
	at kotlinx.coroutines.test.TestCoroutineScheduler.<init>(TestCoroutineScheduler.kt:222)
	at kotlinx.coroutines.test.TestCoroutineDispatchersKt.StandardTestDispatcher(TestCoroutineDispatchers.kt:142)
	at kotlinx.coroutines.test.TestCoroutineDispatchersKt.StandardTestDispatcher$default(TestCoroutineDispatchers.kt:137)
	at kotlinx.coroutines.test.TestScopeKt.withDelaySkipping(TestScope.kt:196)
	at kotlinx.coroutines.test.TestScopeKt.TestScope(TestScope.kt:163)
	at kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0(TestBuilders.kt:167)
	at kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0(Unknown Source)
	at kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0$default(TestBuilders.kt:159)
	at kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0$default(Unknown Source)

However if use runBlocking instead the test run as expected.

Note that, and I don't know if the following is related, if I use kotlin.time.Clock like Clock.System.now(), i get the following error:

java.lang.NoSuchMethodError: 'kotlin.time.Clock kotlin.internal.PlatformImplementations.getSystemClock()'
	at kotlin.time.InstantJvmKt.<clinit>(InstantJvm.kt:12)
	at kotlin.time.Clock$System.now(Clock.kt:60)
@niqo01 niqo01 added the bug label May 5, 2025
@dkhalanskyjb
Copy link
Collaborator

Could not reproduce either of the listed issues:

import kotlinx.coroutines.*
import kotlinx.coroutines.test.*
import kotlin.time.*

fun main() {
    runTest {
        println(Clock.System.now())
    }
}

runs without any issues on https://play.kotlinlang.org with 2.1.20.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants