Skip to content

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

Open
@niqo01

Description

@niqo01

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions