Error while launching a coroutine

Answered

Do you know why I'm getting an error while trying to launch a Coroutine when running my plugin:

GlobalScope.launch(Dispatchers.IO) {
}


Error:

java.lang.ExceptionInInitializerError
at kotlin.random.Random.<clinit>(Random.kt:242)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.<init>(CoroutineScheduler.kt:638)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.<init>(CoroutineScheduler.kt:593)
at kotlinx.coroutines.scheduling.CoroutineScheduler.createNewWorker(CoroutineScheduler.kt:482)
at kotlinx.coroutines.scheduling.CoroutineScheduler.tryCreateWorker(CoroutineScheduler.kt:440)
at kotlinx.coroutines.scheduling.CoroutineScheduler.signalBlockingWork(CoroutineScheduler.kt:421)
at kotlinx.coroutines.scheduling.CoroutineScheduler.dispatch(CoroutineScheduler.kt:402)
at kotlinx.coroutines.scheduling.ExperimentalCoroutineDispatcher.dispatchWithContext$kotlinx_coroutines_core(Dispatcher.kt:111)
at kotlinx.coroutines.scheduling.LimitingDispatcher.dispatch(Dispatcher.kt:164)
at kotlinx.coroutines.scheduling.LimitingDispatcher.dispatch(Dispatcher.kt:154)
at kotlinx.coroutines.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:288)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:26)
at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:109)
at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:158)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
at kotlinx.coroutines.BuildersKt.launch(Unknown Source)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:49)
at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source)
at MyToolWindowFactory.createToolWindowContent(MyToolWindowFactory.kt:28)
at com.intellij.openapi.wm.impl.ToolWindowImpl.ensureContentInitialized(ToolWindowImpl.java:534)
at com.intellij.openapi.wm.impl.ToolWindowManagerImpl.lambda$initToolWindow$10(ToolWindowManagerImpl.java:511)
at com.intellij.openapi.wm.impl.ToolWindowManagerImpl.initToolWindow(ToolWindowManagerImpl.java:514)
at com.intellij.openapi.wm.impl.ToolWindowManagerImpl$6.run(ToolWindowManagerImpl.java:465)
at com.intellij.openapi.wm.impl.CommandProcessor.runNext(CommandProcessor.java:78)
at com.intellij.openapi.wm.impl.CommandProcessor.run(CommandProcessor.java:59)
at com.intellij.openapi.wm.impl.commands.FinalizableCommand.finish(FinalizableCommand.java:36)
at com.intellij.openapi.wm.impl.ToolWindowsPane$AddToolStripeButtonCmd.run(ToolWindowsPane.java:990)
at com.intellij.openapi.wm.impl.CommandProcessor.runNext(CommandProcessor.java:78)
at com.intellij.openapi.wm.impl.CommandProcessor.run(CommandProcessor.java:59)
at com.intellij.openapi.wm.impl.CommandProcessor.flush(CommandProcessor.java:32)
at com.intellij.openapi.wm.impl.ToolWindowManagerImpl.flushCommands(ToolWindowManagerImpl.java:597)
at com.intellij.openapi.wm.impl.ToolWindowManagerImpl.access$3100(ToolWindowManagerImpl.java:74)
at com.intellij.openapi.wm.impl.ToolWindowManagerImpl$InitToolWindowsActivity.lambda$runActivity$0(ToolWindowManagerImpl.java:2367)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:906)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:779)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:422)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:687)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:421)
at com.intellij.ide.IdeEventQueue.pumpEventsForHierarchy(IdeEventQueue.java:963)
at com.intellij.openapi.progress.util.ProgressWindow.startBlocking(ProgressWindow.java:193)
at com.intellij.openapi.progress.util.ProgressWindow.startBlocking(ProgressWindow.java:179)
at com.intellij.openapi.application.impl.ApplicationImpl.runProcessWithProgressSynchronously(ApplicationImpl.java:455)
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcessWithProgressSynchronously(CoreProgressManager.java:453)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcessWithProgressSynchronously(ProgressManagerImpl.java:82)
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcessWithProgressSynchronously(CoreProgressManager.java:250)
at com.intellij.platform.ProjectUiFrameAllocator$run$1.run(ProjectFrameAllocator.kt:64)
at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:83)
at com.intellij.openapi.application.TransactionGuardImpl.submitTransactionAndWait(TransactionGuardImpl.java:149)
at com.intellij.platform.ProjectUiFrameAllocator.run(ProjectFrameAllocator.kt:62)
at com.intellij.platform.PlatformProjectOpenProcessor.openExistingProject(PlatformProjectOpenProcessor.java:234)
at com.intellij.ide.RecentProjectsManagerBase.openProject(RecentProjectsManagerBase.kt:379)
at com.intellij.ide.RecentProjectsManagerBase.reopenLastProjectsOnStart(RecentProjectsManagerBase.kt:467)
at com.intellij.idea.IdeStarter$main$4.run(ApplicationLoader.kt:533)
at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:83)
at com.intellij.openapi.application.TransactionGuardImpl.lambda$submitTransaction$1(TransactionGuardImpl.java:107)
at com.intellij.openapi.application.TransactionGuardImpl.submitTransaction(TransactionGuardImpl.java:116)
at com.intellij.openapi.application.TransactionGuard.submitTransaction(TransactionGuard.java:121)
at com.intellij.idea.IdeStarter.main(ApplicationLoader.kt:523)
at com.intellij.idea.ApplicationLoader$startApp$8$1.run(ApplicationLoader.kt:242)
at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:193)
at com.intellij.idea.ApplicationLoader$startApp$8.run(ApplicationLoader.kt:241)
at java.base/java.util.concurrent.CompletableFuture$UniRun.tryFire(CompletableFuture.java:783)
at java.base/java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:478)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:906)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:779)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:422)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:698)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:421)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.ClassCastException: Instance classloader: com.intellij.util.lang.UrlClassLoader@cb5822, base type classloader: PluginClassLoader[app_name, 0.0.1] com.intellij.ide.plugins.cl.PluginClassLoader@3e71da83
at kotlin.internal.PlatformImplementationsKt.<clinit>(PlatformImplementations.kt:54)
... 88 more
Caused by: java.lang.ClassCastException: class kotlin.internal.jdk8.JDK8PlatformImplementations cannot be cast to class kotlin.internal.PlatformImplementations (kotlin.internal.jdk8.JDK8PlatformImplementations is in unnamed module of loader com.intellij.util.lang.UrlClassLoader @cb5822; kotlin.internal.PlatformImplementations is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @3e71da83)
... 89 more


While this works fine:

GlobalScope.launch(Dispatchers.Swing) {
}


Also not sure if it's related in any way, I also see this error:

[ERROR] [system.err] Exception "java.lang.ClassNotFoundException: org/jetbrains/kotlin/idea/codeInsight/KotlinReferenceData"while constructing DataFlavor for: application/x-java-jvm-local-objectref; class=org.jetbrains.kotlin.idea.codeInsight.KotlinReferenceData


I'm using:

kotlin 1.4.0
coroutines 1.3.9

 

1 comment
Comment actions Permalink

The error is caused because you're mixing implementation(kotlin("stdlib")) with implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.9") dependency which expects some classes which are missing from kotlin-stdlib. This can be easily fixed by using compatible dependencies:

implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.9")

Here's a good article explaining the difference between different versions of stdlib: https://medium.com/@mbonnin/the-different-kotlin-stdlibs-explained-83d7c6bf293

Also this question might help you Which standard library to use in Kotlin

0

Please sign in to leave a comment.