loader constraint violation when using Coroutines

Answered

I am trying to use coroutines in my plugin to hopefully prevent UI freezing. I tried to use executeOnPooledThread, but it did not seem to free up the UI, and often even locked the whole IDE up on startup.

When trying to use Coroutines I have been receiving "loader constraint violation" errors. I am trying to develop for 2019.3 and on.

I have tried excluding Coroutines from Gradle but that causes class cast exceptions.

I am not sure how to use coroutines in my IntelliJ plugin.

I need to match up files inside the project, but the matches are not straight forward, and a project typically has hundreds of these files. It can take a minute or two if any of the files is open (As it does not do any matching until one of these files is opened). Freezing the UI this long is of course unacceptable.

Below is the stack trace for when I include coroutines.

2022-01-15 16:57:07,206 [ 12367] ERROR - llij.ide.plugins.PluginManager - loader constraint violation: when resolving method 'java.lang.Object org.jetbrains.concurrency.Promise_coroutinesKt.await(org.jetbrains.concurrency.Promise, kotlin.coroutines.Continuation)' the class loader com.intellij.ide.plugins.cl.PluginClassLoader @1150203 of the current class, com/badahori/creatures/plugins/intellij/agenteering/indices/BodyPartsIndexKt, and the class loader com.intellij.util.lang.UrlClassLoader @6d8a00e3 for the method's defining class, org/jetbrains/concurrency/Promise_coroutinesKt, have different Class objects for the type kotlin/coroutines/Continuation used in the signature (com.badahori.creatures.plugins.intellij.agenteering.indices.BodyPartsIndexKt is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @1150203, parent loader 'bootstrap'; org.jetbrains.concurrency.Promise_coroutinesKt is in unnamed module of loader com.intellij.util.lang.UrlClassLoader @6d8a00e3, parent loader 'platform') 
java.lang.LinkageError: loader constraint violation: when resolving method 'java.lang.Object org.jetbrains.concurrency.Promise_coroutinesKt.await(org.jetbrains.concurrency.Promise, kotlin.coroutines.Continuation)' the class loader com.intellij.ide.plugins.cl.PluginClassLoader @1150203 of the current class, com/badahori/creatures/plugins/intellij/agenteering/indices/BodyPartsIndexKt, and the class loader com.intellij.util.lang.UrlClassLoader @6d8a00e3 for the method's defining class, org/jetbrains/concurrency/Promise_coroutinesKt, have different Class objects for the type kotlin/coroutines/Continuation used in the signature (com.badahori.creatures.plugins.intellij.agenteering.indices.BodyPartsIndexKt is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @1150203, parent loader 'bootstrap'; org.jetbrains.concurrency.Promise_coroutinesKt is in unnamed module of loader com.intellij.util.lang.UrlClassLoader @6d8a00e3, parent loader 'platform')
at com.badahori.creatures.plugins.intellij.agenteering.indices.BodyPartsIndexKt.readNonBlocking(BodyPartsIndex.kt:601)
at com.badahori.creatures.plugins.intellij.agenteering.indices.BodyPartsIndex.matchSpritesToAtts(BodyPartsIndex.kt:162)
at com.badahori.creatures.plugins.intellij.agenteering.indices.BodyPartsIndex.variantParts(BodyPartsIndex.kt:76)
at com.badahori.creatures.plugins.intellij.agenteering.indices.BodyPartsIndex.variantParts$default(BodyPartsIndex.kt:62)
at com.badahori.creatures.plugins.intellij.agenteering.indices.BodyPartsIndex.variantParts(BodyPartsIndex.kt:58)
at com.badahori.creatures.plugins.intellij.agenteering.att.editor.pose.PoseEditorModel$updateFiles$1.invokeSuspend(PoseEditorModel.kt:66)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
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)

 

And here is the stack trace if I exclude coroutines:

2022-01-15 17:05:16,678 [ 18205] ERROR - llij.ide.plugins.PluginManager - class kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$IntrinsicsKt__IntrinsicsJvmKt$4 cannot be cast to class kotlin.coroutines.Continuation (kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$IntrinsicsKt__IntrinsicsJvmKt$4 is in unnamed module of loader com.intellij.util.lang.UrlClassLoader @6d8a00e3; kotlin.coroutines.Continuation is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @211902a9) 
java.lang.ClassCastException: class kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$IntrinsicsKt__IntrinsicsJvmKt$4 cannot be cast to class kotlin.coroutines.Continuation (kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$IntrinsicsKt__IntrinsicsJvmKt$4 is in unnamed module of loader com.intellij.util.lang.UrlClassLoader @6d8a00e3; kotlin.coroutines.Continuation is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @211902a9)
at com.badahori.creatures.plugins.intellij.agenteering.att.editor.pose.PoseEditorModel$requestRender$1.invoke(PoseEditorModel.kt)
at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$IntrinsicsKt__IntrinsicsJvmKt$4.invokeSuspend(IntrinsicsJvm.kt:199)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
1 comment
Comment actions Permalink

Please see this thread for some suggestions https://github.com/JetBrains/gradle-intellij-plugin/issues/454

If not resolved, please share link to your project.

0

Please sign in to leave a comment.