ClassCastException launching
See original GitHub issueKtor Version and Engine Used (client or server and name) kotlin_version=1.3.61 ktor_version=1.3.0-rc2 coroutines_version=1.3.3-native-mt
Describe the bug Calling testNetworkCall() from ViewController#viewDidLoad in iOS leads to a kotlin.ClassCastException
GlobalScope.launch {
HttpClient { }.get {
url {
takeFrom("https://api.basebeta.com")
encodedPath = "/rankings"
}
}
}
Full stacktrace
Uncaught Kotlin exception: kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for AwaitContinuation(Shareable[used]){HttpResponseData=(statusCode=200 OK)}@cb3ac8. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
at 0 BaseBetaCommonApi 0x0000000111c1ac63 kfun:kotlin.Error.<init>(kotlin.String?;kotlin.Throwable?)kotlin.Error + 115
at 1 BaseBetaCommonApi 0x0000000111d20703 kfun:kotlinx.coroutines.CoroutinesInternalError.<init>(kotlin.String;kotlin.Throwable)kotlinx.coroutines.CoroutinesInternalError + 115
at 2 BaseBetaCommonApi 0x0000000111d86cba kfun:kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx-coroutines-core(kotlin.Throwable?;kotlin.Throwable?) + 938
at 3 BaseBetaCommonApi 0x0000000111d868b0 kfun:kotlinx.coroutines.DispatchedTask.run() + 3568
at 4 BaseBetaCommonApi 0x0000000111d1b908 kfun:kotlinx.coroutines.EventLoopImplBase.processNextEvent()ValueType + 792
at 5 BaseBetaCommonApi 0x0000000111da26f1 kfun:kotlinx.coroutines.runEventLoop$kotlinx-coroutines-core(kotlinx.coroutines.EventLoop?;kotlin.Function0<kotlin.Boolean>) + 881
at 6 BaseBetaCommonApi 0x0000000111da9d12 kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.start$lambda-0#internal + 402
at 7 BaseBetaCommonApi 0x0000000111da9efb kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$146.invoke#internal + 59
at 8 BaseBetaCommonApi 0x0000000111da9f5b kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$146.$<bridge-UNN>invoke()#internal + 59
at 9 BaseBetaCommonApi 0x0000000111c4fd31 WorkerLaunchpad + 177
at 10 BaseBetaCommonApi 0x0000000112052d89 _ZN6Worker19processQueueElementEb + 2569
at 11 BaseBetaCommonApi 0x0000000112053336 _ZN12_GLOBAL__N_113workerRoutineEPv + 54
at 12 libsystem_pthread.dylib 0x00007fff51bfe2eb _pthread_body + 126
at 13 libsystem_pthread.dylib 0x00007fff51c01249 _pthread_start + 66
at 14 libsystem_pthread.dylib 0x00007fff51bfd40d thread_start + 13
Caused by: kotlin.ClassCastException: kotlin.coroutines.native.internal.CompletedContinuation cannot be cast to kotlinx.coroutines.DispatchedContinuation
at 0 BaseBetaCommonApi 0x0000000111c21227 kfun:kotlin.Throwable.<init>(kotlin.String?)kotlin.Throwable + 87
at 1 BaseBetaCommonApi 0x0000000111c1a585 kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception + 85
at 2 BaseBetaCommonApi 0x0000000111c1a0c5 kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException + 85
at 3 BaseBetaCommonApi 0x0000000111c1ae65 kfun:kotlin.ClassCastException.<init>(kotlin.String?)kotlin.ClassCastException + 85
at 4 BaseBetaCommonApi 0x0000000111c6ba5b ThrowClassCastException + 939
at 5 BaseBetaCommonApi 0x0000000111d14ef8 kfun:kotlinx.coroutines.CoroutineDispatcher.releaseInterceptedContinuation(kotlin.coroutines.Continuation<#STAR>) + 216
at 6 BaseBetaCommonApi 0x0000000111c42400 kfun:kotlin.coroutines.native.internal.ContinuationImpl.releaseIntercepted() + 768
at 7 BaseBetaCommonApi 0x0000000111c42a62 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) + 1234
at 8 BaseBetaCommonApi 0x0000000111e8cbf2 kfun:io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith#internal + 930
at 9 BaseBetaCommonApi 0x0000000111e8c773 kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal + 1699
at 10 BaseBetaCommonApi 0x0000000111e8e651 kfun:io.ktor.util.pipeline.SuspendFunctionGun.object-1.resumeWith#internal + 353
at 11 BaseBetaCommonApi 0x0000000111c42b28 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) + 1432
at 12 BaseBetaCommonApi 0x0000000111e8cbf2 kfun:io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith#internal + 930
at 13 BaseBetaCommonApi 0x0000000111e8c773 kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal + 1699
at 14 BaseBetaCommonApi 0x0000000111e8e651 kfun:io.ktor.util.pipeline.SuspendFunctionGun.object-1.resumeWith#internal + 353
at 15 BaseBetaCommonApi 0x0000000111c42b28 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) + 1432
at 16 BaseBetaCommonApi 0x0000000111e8cbf2 kfun:io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith#internal + 930
at 17 BaseBetaCommonApi 0x0000000111e8c773 kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal + 1699
at 18 BaseBetaCommonApi 0x0000000111e8e651 kfun:io.ktor.util.pipeline.SuspendFunctionGun.object-1.resumeWith#internal + 353
at 19 BaseBetaCommonApi 0x0000000111c42b28 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) + 1432
at 20 BaseBetaCommonApi 0x0000000111d8659c kfun:kotlinx.coroutines.DispatchedTask.run() + 2780
at 21 BaseBetaCommonApi 0x0000000111d1b908 kfun:kotlinx.coroutines.EventLoopImplBase.processNextEvent()ValueType + 792
at 22 BaseBetaCommonApi 0x0000000111da26f1 kfun:kotlinx.coroutines.runEventLoop$kotlinx-coroutines-core(kotlinx.coroutines.EventLoop?;kotlin.Function0<kotlin.Boolean>) + 881
at 23 BaseBetaCommonApi 0x0000000111da9d12 kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.start$lambda-0#internal + 402
at 24 BaseBetaCommonApi 0x0000000111da9efb kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$146.invoke#internal + 59
at 25 BaseBetaCommonApi 0x0000000111da9f5b kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$146.$<bridge-UNN>invoke()#internal + 59
at 26 BaseBetaCommonApi 0x0000000111c4fd31 WorkerLaunchpad + 177
at 27 BaseBetaCommonApi 0x0000000112052d89 _ZN6Worker19processQueueElementEb + 2569
at 28 BaseBetaCommonApi 0x0000000112053336 _ZN12_GLOBAL__N_113workerRoutineEPv + 54
at 29 libsystem_pthread.dylib 0x00007fff51bfe2eb _pthread_body + 126
To Reproduce Copy and paste the code snippet from above into the common module of a multiplatform project. Run the function from ViewController#viewDidLoad in the iOS app.
Expected behavior I expect the code to execute without throwing a ClassCastException.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Explanation of ClassCastException in Java - Stack Overflow
It's really pretty simple: if you are trying to typecast an object of class A into an object of class B, and they...
Read more >Handling the ClassCastException Runtime Exception in Java
The ClassCastException in Java happens when the JVM tries to cast an object to a class (or in some instances, an interface) and...
Read more >Explanation of ClassCastException in Java - Baeldung
ClassCastException is an unchecked exception that signals the code has attempted to cast a reference to a type of which it's not a...
Read more >PM80589: JAVA.LANG.CLASSCASTEXCEPTION AFTER AN ...
A ClassCastException occurs after an application restart because WebSphere Application Server continues to hold references to the application.
Read more >class java.util.concurrent.TimeoutException cannot be cast to ...
ClassCastException : class java.util.concurrent.TimeoutException cannot be cast to ... withContextLoader(Launch.scala:176) at xsbt.boot.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Getting the same crash with ktor 1.4.1 and coroutines 1.3.9-native-mt-2. How can we fix it?
It seems there is an issue with Kotlin 1.4.10, according to this https://github.com/Kotlin/kotlinx.coroutines/issues/2295 I downgraded ktor to 1.3.2, Kotlin back to version 1.3.72 and coroutines to 1.3.7 and only then it worked, not sure if maybe I had something cached somewhere and it was still compiling with Kotlin 1.4