Skip to content

Exception in coroutines machinery (ClassCastException) affecting only few android 5 users #2763

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

Closed
Dmitry-Borodin opened this issue Jun 14, 2021 · 24 comments

Comments

@Dmitry-Borodin
Copy link
Contributor

Dmitry-Borodin commented Jun 14, 2021

Kotlin 1.5.10, coroutines 1.4.3 (checked changelog - looks like not fixed)
This is happening to 200 users (800 crashes) only on android 5 (I have at least 8000 android 5 users in last week.)
Not reproducible.

Fatal Exception: kotlinx.coroutines.m0: Fatal exception in coroutines machinery for CancellableContinuation(DispatchedContinuation[Dispatchers.Default, Continuation at package.Repository$updateCacheVariants$1.invokeSuspend(Repository.kt)@2b36bba8]){Cancelled}@a821e66. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
       at kotlinx.coroutines.DispatchedTask.handleFatalException(DispatchedTask.java:144)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:115)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:571)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.java:750)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.java:678)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:665)
Caused by java.lang.ClassCastException: kotlin.a0.k.a.c cannot be cast to kotlinx.coroutines.internal.e
       at kotlinx.coroutines.CoroutineDispatcher.releaseInterceptedContinuation(CoroutineDispatcher.java:104)
       at kotlin.coroutines.jvm.internal.ContinuationImpl.releaseIntercepted(ContinuationImpl.java:118)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:39)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:104)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:571)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.java:750)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.java:678)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:665)

While I'm investigating why stacktrace is obfuscated (Firebase should deobfuscate stacktraces automatically), reporting it now so you may have some feedback.

The code in referenced repository is as following

 		GlobalScope.launch {
			try {
// generated retrofit suspend function and access property of response model
				val response: List<Variants> = retrofitService.getAllVariants(request).variants 
				cachedVariants.saveVariantsToCache(response)
			}
			catch (e: Exception) {
				logCouldntSaveCache()
			}
                 }
@Dmitry-Borodin Dmitry-Borodin changed the title Exception in coroutines machinery (ClassCastException) affecting only few users in android 5 Exception in coroutines machinery (ClassCastException) affecting only few android 5 users Jun 14, 2021
@qwwdfsad
Copy link
Member

Could be the same as #2736.
Could you please elaborate on how did you manage to connect the exception with the given snippet?
If it is an Anroid issue, probably extracting launch body to a separate method (along with try/catch) may help

@Dmitry-Borodin
Copy link
Contributor Author

Dmitry-Borodin commented Jun 16, 2021

Could you please elaborate on how did you manage to connect the exception with the given snippet?

In error message (first line of stacktrace) there is a reference "Continuation at <....>.Repository$updateCacheVariants$1.invokeSuspend(Repository.kt)@2b36bba8]){Cancelled}@a821e66" -
In this file in this method there is only one suspend call, Simplified version of which is provided.

If it is an Anroid issue, probably extracting launch body to a separate method (along with try/catch) may help

Thank you will try it out.

@qwwdfsad qwwdfsad added the bug label Jul 5, 2021
@Dmitry-Borodin
Copy link
Contributor Author

I can add that extracting launch body to a separate method doesn't help.

@Dmitry-Borodin
Copy link
Contributor Author

Dmitry-Borodin commented Jul 26, 2021

Deobfuscated version

Fatal Exception: kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for CancellableContinuation(DispatchedContinuation[Dispatchers.Default, Continuation at package.Repository$updateCacheVariants$1.invokeSuspend(Repository.kt)@2b36bba8]){Cancelled}@a821e66. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
       at kotlinx.coroutines.DispatchedTask.handleFatalException(DispatchedTask.java:144)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:115)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:571)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.java:750)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.java:678)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:665)
Caused by java.lang.ClassCastException
kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to kotlinx.coroutines.internal.DispatchedContinuation
kotlin.coroutines.jvm.internal.ContinuationImpl.releaseIntercepted (ContinuationImpl.java:118)
kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (BaseContinuationImpl.java:39)
kotlinx.coroutines.DispatchedTask.run (DispatchedTask.java:104)
kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely (CoroutineScheduler.java:571)
kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask (CoroutineScheduler.java:750)
kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker (CoroutineScheduler.java:678)
kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run (CoroutineScheduler.java:665)

So seems the same as #2736 but happening exclusively on android 5 devices.

@qwwdfsad
Copy link
Member

qwwdfsad commented Jul 27, 2021

Could you please elaborate on the coroutines versions? We expect this bug to be fixed in version 1.5.1

@Dmitry-Borodin
Copy link
Contributor Author

I use 1,5,0,
Will update and see how it goes.

@Dmitry-Borodin
Copy link
Contributor Author

This is not fixed in 1.5.1.
I still see this issue rarely and only on Android 5 devices. Stacktrace changed through, probably proguard changed line numbers.

@qwwdfsad
Copy link
Member

Could you please share the new stacktrace?

@lordcodes
Copy link

lordcodes commented Aug 25, 2021

I can reproduce this issue reliably on a Pixel C emulator with Android 10 (API 29). It doesn't happen with same app code on my Pixel 2.

Coroutines version 1.5.1
Kotlin version 1.5.30

2021-08-25 16:08:53.652 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.getbusy.android.getbusy.dev, PID: 9185
kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for CancellableContinuation(DispatchedContinuation[Dispatchers.Main, Continuation at com.getbusy.android.getbusy.authentication.model.UserIdentityRepository.fetchLatestUserIdentity(UserIdentityRepository.kt:20)@852144a]){Cancelled}@85d5fbb. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
        at kotlinx.coroutines.DispatchedTask.handleFatalException(DispatchedTask.kt:144)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:115)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     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.DispatchedTask.run(DispatchedTask.kt:104)
        at android.os.Handler.handleCallback(Handler.java:883) 
        at android.os.Handler.dispatchMessage(Handler.java:100) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7356) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 

The line of app code the stacktrace refers to is just calling a suspend function on a 'Retrofit' interface.

@qwwdfsad
Copy link
Member

Could you please share your reproducer? It would significantly simplify the investigation

@lordcodes
Copy link

lordcodes commented Aug 25, 2021

Could you please share your reproducer? It would significantly simplify the investigation

As in a project? Sorry I can't share the full source code for the project I work on.

I don't think the issue is related to the project it is within, but more the environment, i.e. it happens in Android on the Pixel C emulator from Android studio for me, but not on my physical Pixel 2 device.

This crashes the app the second the app starts when it calls its first suspend function and is reproducible 100% of the time. I.e. it renders the app unusable.

It looks like rolling back to Kotlin 1.5.21 has stopped it happening on every run of the app for me.

@Dmitry-Borodin
Copy link
Contributor Author

Dmitry-Borodin commented Aug 25, 2021

New stacktrace as asked for coroutines 1.5.1. Kotlin version 1.5.21.

Fatal Exception: kotlinx.coroutines.CoroutinesInternalError
Fatal exception in coroutines machinery for CancellableContinuation(DispatchedContinuation[Dispatchers.Default, Continuation at <my.package.class>.loadCacheVariants(Repo.kt)@a667b50]){Cancelled}@17151149. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
Fatal Exception: kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for CancellableContinuation(DispatchedContinuation[Dispatchers.Default, Continuation at <my_package>.loadCacheVariants(Repo.kt)@a667b50]){Cancelled}@17151149. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
       at kotlinx.coroutines.DispatchedTask.handleFatalException(DispatchedTask.java:144)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:115)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:571)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.java:750)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.java:678)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:665)

Caused by java.lang.ClassCastException: kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to kotlinx.coroutines.internal.DispatchedContinuation
       at kotlinx.coroutines.CoroutineDispatcher.releaseInterceptedContinuation(CoroutineDispatcher.java:107)
       at kotlin.coroutines.jvm.internal.ContinuationImpl.releaseIntercepted(ContinuationImpl.java:118)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:39)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:104)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:571)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.java:750)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.java:678)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:665)

For reference, I still see this issue very rarely only on android 5 devices of the users. I cannot reproduce it on emulator.

@Dmitry-Borodin
Copy link
Contributor Author

Dmitry-Borodin commented Aug 25, 2021

Strange thing here is why google Crashlytics doesn't deobfuscate paths for:

kotlinx.coroutines.CoroutinesInternalError
 kotlin.coroutines.jvm.internal.CompletedContinuation
 kotlinx.coroutines.internal.DispatchedContinuation

I have to do it manually from proguard mapping file that was downloading to google together with the app. Other crashes are completely deobfuscated. I don't think it's connected with the issue, but just in case.

@qwwdfsad
Copy link
Member

@lordcodes it would be nice if you could share not the whole application, but only the relevant piece of machinery that crashes, if that is okay with you.
I realize it's a bit of extra work here, but it doesn't seem that I can debug this issue without a reproducer.

Also, please ensure that you are using coroutines 1.5.1 and not i.e. 1.5.0

@lordcodes
Copy link

@qwwdfsad I will try and see if I can create a sample app that has the same issue. However, once it boils down to what is actually crashing it would just be an app that includes Coroutines and calls a suspend function, i.e. like any other project. The project I work on doesn't do anything special with Coroutines, just includes the library and then uses them.

However, when I get a chance I will try and create a small sample project.

@eygraber
Copy link

I have been using coroutines 1.5.0 in my Android project for a while and haven't seen this issue. Last night I updated to Kotlin 1.5.30 and got this crash (I also get it on coroutines 1.5.1):

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.myapp, PID: 9068
    kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for CancellableContinuation(DispatchedContinuation[Dispatchers.Main, Continuation at kotlinx.coroutines.channels.AbstractChannel.receiveCatching-JP2dKIU(AbstractChannel.kt:632)@8eee127]){Cancelled}@179efd4. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
        at kotlinx.coroutines.DispatchedTask.handleFatalException(DispatchedTask.kt:144)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:115)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7664)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     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.internal.ScopeCoroutine.afterResume(Scopes.kt:33)
        at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
        at android.os.Handler.handleCallback(Handler.java:938) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:223) 
        at android.app.ActivityThread.main(ActivityThread.java:7664) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 

It seems to only be happening when I use my observeStateChanges function is used in my awaitFirst function:

suspend inline fun awaitFirst(vararg funcs: suspend () -> Unit) {
  supervisorScope {
    select<Unit> {
      funcs.forEach { func -> launch { func() }.onJoin {} }
    }

    coroutineContext.cancelChildren()
  }
}

suspend fun View.awaitClick() = suspendCancellableCoroutine<Unit> { cont ->
  val listener = View.OnClickListener {
    if(cont.isActive) cont.resume(Unit)
    setOnClickListener(null)
  }

  cont.invokeOnCancellation {
    setOnClickListener(null)
  }

  setOnClickListener(listener)
}

// SlidingLayout is an internal ViewGroup that I use
fun SlidingLayout.observeStateChanges() = callbackFlow<State> {
  val listener = object : OnSlideListener {
    override fun onSlide(state: State, offset: Float) {}

    override fun onStateChange(oldState: State, newState: State) {
      if(!isClosedForSend) offerCatching(newState)
    }
  }

  addOnSlideListener(listener)

  awaitClose {
    removeOnSlideListener(listener)
  }
}

This is how I invoke it at the location that is crashing:

awaitFirst(
    binding.cancel::awaitClick,
    binding.root.observeStateChanges().filter { it == SlidingLayout.State.Hidden }::first
)

If I replace the awaitFirst with binding.cancel::awaitClick or binding.root.observeStateChanges().filter { it == SlidingLayout.State.Hidden }::first then it doesn't crash.

If I downgrade to Kotlin 1.5.21 it doesn't crash with either coroutines 1.5.0 or 1.5.1

I'd say this line looks suspect - https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/common/src/CoroutineDispatcher.kt#L107

@lordcodes
Copy link

If I downgrade to Kotlin 1.5.21 it doesn't crash with either coroutines 1.5.0 or 1.5.1

Those are my findings too, I rolled back to Kotlin 1.5.21 and now everything is working fine. I had never seen this crash until right after I upgraded to Kotlin 1.5.30.

@LouisCAD
Copy link
Contributor

LouisCAD commented Aug 27, 2021

Maybe this issue deserves an entry on YouTrack since it seems to be related to Kotlin 1.5.30? https://kotl.in/issue

@eygraber
Copy link

@OliverO2
Copy link
Contributor

Just for the record (observed only once, cannot reproduce), this has occurred on a non-Android JVM with Kotlin 1.5.31 and coroutines 1.5.2:

version.kotlin=1.5.31
version.kotlinx.coroutines=1.5.2
Amazon Corretto JDK 11.0.12+7-LTS
Linux 5.11.0-34-generic
Ubuntu 20.04.3 LTS
Cores: 4

Stack trace:

Exception in thread "DefaultDispatcher-worker-2" kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for CancellableContinuation(DispatchedContinuation[Dispatchers.Default, Continuation at vc.backendCache.Subscription$modelUpdateBatches$1.invokeSuspend(Subscription.kt:96)@643ad787]){Completed}@6f21b667. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
at kotlinx.coroutines.DispatchedTask.handleFatalException(DispatchedTask.kt:144)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:115)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
Caused by: java.lang.ClassCastException: class kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to class kotlinx.coroutines.internal.DispatchedContinuation (kotlin.coroutines.jvm.internal.CompletedContinuation and kotlinx.coroutines.internal.DispatchedContinuation are in unnamed module of loader 'app')
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.DispatchedTask.run(DispatchedTask.kt:106)
... 4 more

@LouisCAD
Copy link
Contributor

@OliverO2 Can you comment in the YouTrack issue linked above? Ideally, you can also put a reproducing snippet there to help QA reproduce it.

@Dmitry-Borodin
Copy link
Contributor Author

Found another crash, probably related to this one
Kotlin 1.5.30, coroutines 1.5.2. Android 5 devices only and very rare. More rare then stacktrace of initial message.

Fatal Exception: java.lang.ExceptionInInitializerError
Fatal Exception: java.lang.ExceptionInInitializerError
       at kotlinx.coroutines.CoroutineDispatcher.interceptContinuation(CoroutineDispatcher.java:100)
       at kotlin.coroutines.jvm.internal.ContinuationImpl.intercepted(ContinuationImpl.java:112)
       at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt.intercepted(IntrinsicsKt__IntrinsicsJvmKt.java:143)
       at kotlin.coroutines.intrinsics.IntrinsicsKt.intercepted(IntrinsicsKt.java)
       at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(CancellableKt.java:30)
       at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(CancellableKt.java:25)
       at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.java:110)
       at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.java:126)
       at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(BuildersKt__Builders_commonKt.java:56)
       at kotlinx.coroutines.BuildersKt.launch(BuildersKt.java:1)
       at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(BuildersKt__Builders_commonKt.java:47)
       at kotlinx.coroutines.BuildersKt.launch$default(BuildersKt.java:1)

       at <update cache function mentioned above in this issue>
        <...>
       at <app.onCreate()>
       
       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1020)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5245)
       at android.app.ActivityThread.access$1600(ActivityThread.java:181)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1537)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6134)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by java.lang.RuntimeException
java.lang.NoSuchFieldException: _reusableCancellableContinuation
Caused by java.lang.RuntimeException: java.lang.NoSuchFieldException: _reusableCancellableContinuation
       at java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.<init>(AtomicReferenceFieldUpdater.java:202)
       at java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(AtomicReferenceFieldUpdater.java:67)
       at kotlinx.coroutines.internal.DispatchedContinuation.<clinit>(DispatchedContinuation.java)
       at kotlinx.coroutines.CoroutineDispatcher.interceptContinuation(CoroutineDispatcher.java:100)
       at kotlin.coroutines.jvm.internal.ContinuationImpl.intercepted(ContinuationImpl.java:112)
       at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt.intercepted(IntrinsicsKt__IntrinsicsJvmKt.java:143)
       at kotlin.coroutines.intrinsics.IntrinsicsKt.intercepted(IntrinsicsKt.java)
       at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(CancellableKt.java:30)
       at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(CancellableKt.java:25)
       at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.java:110)
       at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.java:126)
       at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(BuildersKt__Builders_commonKt.java:56)
       at kotlinx.coroutines.BuildersKt.launch(BuildersKt.java:1)
       at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(BuildersKt__Builders_commonKt.java:47)
       at kotlinx.coroutines.BuildersKt.launch$default(BuildersKt.java:1)

       at <update cache function mentioned above in this issue>
        <...>
       at <app.onCreate()>

       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1020)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5245)
       at android.app.ActivityThread.access$1600(ActivityThread.java:181)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1537)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6134)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by java.lang.NoSuchFieldException
_reusableCancellableContinuation
Caused by java.lang.NoSuchFieldException: _reusableCancellableContinuation
       at java.lang.Class.getDeclaredField(Class.java:929)
       at java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.<init>(AtomicReferenceFieldUpdater.java:183)
       at java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(AtomicReferenceFieldUpdater.java:67)
       at kotlinx.coroutines.internal.DispatchedContinuation.<clinit>(DispatchedContinuation.java)
       at kotlinx.coroutines.CoroutineDispatcher.interceptContinuation(CoroutineDispatcher.java:100)
       at kotlin.coroutines.jvm.internal.ContinuationImpl.intercepted(ContinuationImpl.java:112)
       at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt.intercepted(IntrinsicsKt__IntrinsicsJvmKt.java:143)
       at kotlin.coroutines.intrinsics.IntrinsicsKt.intercepted(IntrinsicsKt.java)
       at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(CancellableKt.java:30)
       at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(CancellableKt.java:25)
       at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.java:110)
       at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.java:126)
       at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(BuildersKt__Builders_commonKt.java:56)
       at kotlinx.coroutines.BuildersKt.launch(BuildersKt.java:1)
       at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(BuildersKt__Builders_commonKt.java:47)
       at kotlinx.coroutines.BuildersKt.launch$default(BuildersKt.java:1)

       at <update cache function mentioned above in this issue>
        <...>
       at <app.onCreate()>

       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1020)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5245)
       at android.app.ActivityThread.access$1600(ActivityThread.java:181)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1537)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6134)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)`

@qwwdfsad
Copy link
Member

qwwdfsad commented Dec 7, 2021

Fixed in Kotlin 1.6.0

@qwwdfsad qwwdfsad closed this as completed Dec 7, 2021
@brandlee
Copy link

brandlee commented Nov 3, 2022

my Kotlin version is 1.6.10, this bug happened again......

classpath 'com.android.tools.build:gradle:7.0.2'

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"

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

7 participants