{"id":23087674,"url":"https://github.com/gnu11111/ktor-4164-test","last_synced_at":"2025-04-03T16:45:42.024Z","repository":{"id":163746988,"uuid":"490254882","full_name":"gnu11111/ktor-4164-test","owner":"gnu11111","description":"#ktor-2.0 #issue #classloader #classcast #exception","archived":false,"fork":false,"pushed_at":"2022-05-09T12:04:03.000Z","size":293,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-09T05:27:43.870Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gnu11111.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-09T11:31:33.000Z","updated_at":"2022-05-09T11:32:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"d31ee70d-9d25-4970-95b6-660e49b16bf9","html_url":"https://github.com/gnu11111/ktor-4164-test","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnu11111%2Fktor-4164-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnu11111%2Fktor-4164-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnu11111%2Fktor-4164-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnu11111%2Fktor-4164-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gnu11111","download_url":"https://codeload.github.com/gnu11111/ktor-4164-test/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247043242,"owners_count":20874084,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-16T19:59:39.593Z","updated_at":"2025-04-03T16:45:42.019Z","avatar_url":"https://github.com/gnu11111.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [KTOR-4164: Different ClassLoader behaviour in Ktor-2.0.0 (vs. Ktor-1.6.x) produces a ClassCastException within a CouroutineScope](https://youtrack.jetbrains.com/issue/KTOR-4164)\n\nIn a CoroutineScope of a Ktor-2.0.0-application (netty-engine), the \"ClassLoaders@AppClassLoader\" is not aware of Objects loaded by the (default?) Application ClassLoader. Therefore, for exampe, received objects from an (Apache-ActiveMQ-Artemis-)message-queue cannot be cast to its corresponding DTOs - see attached screenshots with Ktor-1.6.8/Kotlin-1.6.10 vs. Ktor-2.0.0/Kotlin-1.6.20.\n\n![ClassLoder with Ktor-1.6.8](ClassLoaderKtor_1_6_8.png) ![ClassLoder with Ktor-2.0.0](ClassLoaderKtor_2_0_0.png)\n\n\n# To reproduce the error:\n\n1) get and start the Apache ActiveMQ Artemis - message broker:\n\n\u003cpre\u003e\u003ccode\u003e\nwget https://downloads.apache.org/activemq/activemq-artemis/2.22.0/apache-artemis-2.22.0-bin.tar.gz\n\ntar xfz apache-artemis-2.22.0-bin.tar.gz\n\napache-artemis-2.22.0/bin/artemis create ktor-test # username: test / password: test / anonymous access: Y\n\nktor-test/bin/artemis run\n\u003c/code\u003e\u003c/pre\u003e\n\n2) either run the `com.example.ApplicationTest` or run the Ktor-application in \"development\"-mode (`-Dio.ktor.development=true`) and start the `com.example.MessageProducer` afterwards.\n**FYI: Everything works fine in \"normal\"-mode (`-Dio.ktor.development=false`) and the class cast exception doesn't occur!**\n\n\u003cpre\u003e\u003ccode\u003e\n2022-05-09 13:14:23.841 [DefaultDispatcher-worker-1] INFO  ktor.application - Received Test object as JSON message: Test(id=1)\nException in thread \"DefaultDispatcher-worker-1\" java.lang.ClassCastException: class com.example.dto.Test cannot be cast to class com.example.dto.Test (com.example.dto.Test is in unnamed module of loader 'app'; com.example.dto.Test is in unnamed module of loader io.ktor.server.engine.OverridingClassLoader$ChildURLClassLoader @1c7696c6)\n\tat com.example.plugins.MessageQueueKt$configureMessageQueue$1.invokeSuspend(MessageQueue.kt:39)\n\tat kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)\n\tat kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)\n\tat kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)\n\tat kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)\n\tat kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)\n\tat kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)\n\tSuppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@561bd503, Dispatchers.Default]\n\u003c/code\u003e\u003c/pre\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgnu11111%2Fktor-4164-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgnu11111%2Fktor-4164-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgnu11111%2Fktor-4164-test/lists"}