kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to kotlinx.coroutines.internal.DispatchedContinuation

See original GitHub issue

I have this crash on runtime with Kotlin 1.5.31 and kotlinx.coroutines 1.5.2. I use BOM for Kotlin and corouties with enforcePlatform, so it looks that correct version is used on runtime

It looks exactly the same as https://github.com/Kotlin/kotlinx.coroutines/issues/2736 but this issue was closed and fix available in 1.5.2

So I report it separately.

kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for CancellableContinuation(DispatchedContinuation[Dispatchers.Main.immediate, Continuation at com.bandlab.listmanager.pagination.impl.PaginationListManagerImpl.reload$suspendImpl(PaginationListManagerImpl.kt:223)@ed822fb]){Cancelled}@5d18f18. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
        at kotlinx.coroutines.DispatchedTask.handleFatalException(DispatchedTask.kt:144)
        at kotlinx.coroutines.DispatchedTaskKt.resumeUnconfined(DispatchedTask.kt:251)
        at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:161)
        at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397)
        at kotlinx.coroutines.CancellableContinuationImpl.cancel(CancellableContinuationImpl.kt:183)
        at kotlinx.coroutines.CancellableContinuationImpl.parentCancelled$kotlinx_coroutines_core(CancellableContinuationImpl.kt:190)
        at kotlinx.coroutines.ChildContinuation.invoke(JobSupport.kt:1474)
        at kotlinx.coroutines.JobSupport.completeStateFinalization(JobSupport.kt:318)
        at kotlinx.coroutines.JobSupport.tryFinalizeSimpleState(JobSupport.kt:295)
        at kotlinx.coroutines.JobSupport.tryMakeCompleting(JobSupport.kt:856)
        at kotlinx.coroutines.JobSupport.makeCompletingOnce$kotlinx_coroutines_core(JobSupport.kt:828)
        at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:100)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
        at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:234)
        at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:166)
        at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397)
        at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:431)
        at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default(CancellableContinuationImpl.kt:420)
        at kotlinx.coroutines.CancellableContinuationImpl.resumeUndispatched(CancellableContinuationImpl.kt:518)
        at kotlinx.coroutines.android.HandlerContext$scheduleResumeAfterDelay$$inlined$Runnable$1.run(Runnable.kt:19)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7842)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
     Caused by: java.lang.ClassCastException: kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to kotlinx.coroutines.internal.DispatchedContinuation
        at kotlinx.coroutines.CoroutineDispatcher.releaseInterceptedContinuation(CoroutineDispatcher.kt:107)
        at kotlin.coroutines.jvm.internal.ContinuationImpl.releaseIntercepted(ContinuationImpl.kt:118)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:39)
        at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:234)
        at kotlinx.coroutines.DispatchedTaskKt.resumeUnconfined(DispatchedTask.kt:190)
        at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:161) 
        at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397) 
        at kotlinx.coroutines.CancellableContinuationImpl.cancel(CancellableContinuationImpl.kt:183) 
        at kotlinx.coroutines.CancellableContinuationImpl.parentCancelled$kotlinx_coroutines_core(CancellableContinuationImpl.kt:190) 
        at kotlinx.coroutines.ChildContinuation.invoke(JobSupport.kt:1474) 
        at kotlinx.coroutines.JobSupport.completeStateFinalization(JobSupport.kt:318) 
        at kotlinx.coroutines.JobSupport.tryFinalizeSimpleState(JobSupport.kt:295) 
        at kotlinx.coroutines.JobSupport.tryMakeCompleting(JobSupport.kt:856) 
        at kotlinx.coroutines.JobSupport.makeCompletingOnce$kotlinx_coroutines_core(JobSupport.kt:828) 
        at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:100) 
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46) 
        at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:234) 
        at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:166) 
        at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397) 
        at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:431) 
        at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default(CancellableContinuationImpl.kt:420) 
        at kotlinx.coroutines.CancellableContinuationImpl.resumeUndispatched(CancellableContinuationImpl.kt:518) 
        at kotlinx.coroutines.android.HandlerContext$scheduleResumeAfterDelay$$inlined$Runnable$1.run(Runnable.kt:19) 
        at android.os.Handler.handleCallback(Handler.java:938) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loopOnce(Looper.java:201) 
        at android.os.Looper.loop(Looper.java:288) 
        at android.app.ActivityThread.main(ActivityThread.java:7842) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

13reactions
qwwdfsadcommented, Jan 17, 2022

I’ve found the root cause: https://youtrack.jetbrains.com/issue/KT-50832

As a workaround, please avoid method-references to suspend inline functions and use a plain lambda instead (e.g. ::WebWebSocketSession -> { WebSocketSession(it) }

1reaction
qwwdfsadcommented, Nov 1, 2021

Can I ask you an unrelated question about Kotlin coroutines cancellation? documented here.

Sure, you can reach me out in public Slack (Vsevolod Tolstopyatov [JB]). I’m out of the context of what this code actually does and in need of some details to actually answer that

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.ClassCastException: kotlin.coroutines.jvm.internal ...
CompletedContinuation cannot be cast to kotlinx.coroutines.internal.DispatchedContinuation #2736 ... DispatchedContinuation (kotlin.coroutines.jvm.internal.
Read more >
ClassCastException: CompletedContinuation cannot be cast ...
I have a small library that uses coroutines but currently it's broken because of internal coroutine exception, which I can't handle by myself....
Read more >
kotlinx.coroutines.CompletableDeferredImpl cannot be cast to ...
That cast is very suspicious since it should work even without it. That means your cast is invalid, causing the error you're seeing....
Read more >
Package kotlinx.coroutines
CoroutineDispatcher that provides a method to close it, causing the rejection of any new tasks and cleanup of all underlying resources associated with...
Read more >
Kotlinx.Coroutines.Completabledeferredimpl Cannot Be Cast ...
ClassCastException: kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to kotlinx.coroutines.internal.DispatchedContinuation #2736.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found