Daniel Ciocirlan
04/22/2024, 10:41 AMraceN
combinator and I've just hit a NoClassDefFound
error. I was using Arrow 1.2.4 with kotlinx.coroutines 1.6.4 and looking at the implementation of race
, it seems it's using the experimental select feature which is throwing a ClassNotFound for some SelectImplementation
that it didn't find. Upgrading to kotlinx.coroutines 1.8.0 solved this for me.
Is this expected? Worth enforcing in the library dependencies or at least mentioning in the docs?Alejandro Serrano.Mena
04/22/2024, 11:02 AMkotlinx.coroutines
, and since the automatic dependency update was green, we proceeded with itAlejandro Serrano.Mena
04/22/2024, 11:03 AMDaniel Ciocirlan
04/22/2024, 11:45 AMsuspend fun main() {
suspend fun weirdRace() {
val race = raceN (
{ delay(500); 42 },
{ delay(700); 43 },
)
println(race)
}
weirdRace()
}
trace:
Exception in thread "main" java.lang.NoClassDefFoundError: kotlinx/coroutines/selects/SelectImplementation
at com.rockthejvm.weird.ParallelOpsKt$main$weirdcom.rockthejvm.weird$$inlined$com.rockthejvm.weirdN$1.invokeSuspend(com.rockthejvm.weird2.kt:112)
at com.rockthejvm.weird.ParallelOpsKt$main$weirdcom.rockthejvm.weird$$inlined$com.rockthejvm.weirdN$1.invoke(com.rockthejvm.weird2.kt)
at com.rockthejvm.weird.ParallelOpsKt$main$weirdcom.rockthejvm.weird$$inlined$com.rockthejvm.weirdN$1.invoke(com.rockthejvm.weird2.kt)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:264)
at com.rockthejvm.weird.ParallelOpsKt.main$weirdcom.rockthejvm.weird(ParallelOps.kt:157)
at com.rockthejvm.weird.ParallelOpsKt.main(ParallelOps.kt:123)
at com.rockthejvm.weird.ParallelOpsKt$main$2.invoke(ParallelOps.kt)
at com.rockthejvm.weird.ParallelOpsKt$main$2.invoke(ParallelOps.kt)
at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$IntrinsicsKt__IntrinsicsJvmKt$1.invokeSuspend(IntrinsicsJvm.kt:270)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlin.coroutines.ContinuationKt.startCoroutine(Continuation.kt:115)
at kotlin.coroutines.jvm.internal.RunSuspendKt.runSuspend(RunSuspend.kt:19)
at com.rockthejvm.weird.ParallelOpsKt.main(ParallelOps.kt)
Caused by: java.lang.ClassNotFoundException: kotlinx.coroutines.selects.SelectImplementation
simon.vergauwen
04/22/2024, 11:46 AMAlejandro Serrano.Mena
04/22/2024, 11:48 AMDaniel Ciocirlan
04/22/2024, 11:58 AMsuspend fun weirdRace() {
val race =
coroutineScope {
val a = async(this.coroutineContext) { delay(500); 42 }
val b = async(this.coroutineContext) { delay(700); 43 }
select<Either<Int, Int>> {
a.onAwait.invoke { Either.Left(it) }
b.onAwait.invoke { Either.Right(it) }
}.also {
when (it) {
is Either.Left -> b.cancelAndJoin()
is Either.Right -> a.cancelAndJoin()
}
}
}
println(race)
}
simon.vergauwen
04/22/2024, 12:05 PMDaniel Ciocirlan
04/22/2024, 12:09 PMDaniel Ciocirlan
04/22/2024, 12:13 PMselect
since 1.7.0, and indeed 1.7.0 seems to be enough (just tested)Alejandro Serrano.Mena
04/22/2024, 12:46 PMsimon.vergauwen
04/22/2024, 1:00 PMsimon.vergauwen
04/22/2024, 1:00 PMAlejandro Serrano.Mena
04/22/2024, 1:03 PMsimon.vergauwen
04/22/2024, 1:05 PMAlejandro Serrano.Mena
04/22/2024, 1:15 PMinline
, which assumes that your implementation doesn't change between versions (in fact, I'm not happy that select
is marked as inline
in the coroutines library to being with)
should we introduce a warning in Arrow's website? Something similar to:
The Arrow team follows an eager dependency update policy. That means that Arrow libraries always depend on the most up-to-date version of the dependencies at the moment of release. In most cases it's fine to use older version of the dependencies, but in rare cases the conflict leads to NoClassDefFoundError. In that case, please try to update your dependencies to a more recent version, or open an issue.although I'm not sure which is the best page in the docs to have it
Daniel Ciocirlan
04/22/2024, 1:22 PMAlejandro Serrano.Mena
04/22/2024, 1:30 PMDaniel Ciocirlan
04/22/2024, 1:32 PMsimon.vergauwen
04/22/2024, 1:42 PM