Idea throws ConcurrentModificationException for the "Kotlin scripting examples" repo

I wanted to try out custom Kotlin scripting, as described here.

When I open the kotlin-script-examples Github Repo with Idea-2022.1 (Ubuntu-21.10, Java-17) and view the Idea log file, I see the following exceptions:

2022-04-30 21:25:27,007 [ 737775]   WARN - #o.j.k.i.script - [KOTLIN_SCRIPTING] java.util.ConcurrentModificationException 
java.util.ConcurrentModificationException
       at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1043)
       at java.base/java.util.ArrayList$Itr.next(ArrayList.java:997)
       at kotlin.script.experimental.dependencies.maven.impl.AetherResolveSession$remotes$2.invoke(aether.kt:277)
       at kotlin.script.experimental.dependencies.maven.impl.AetherResolveSession$remotes$2.invoke(aether.kt:52)
       at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
       at kotlin.script.experimental.dependencies.maven.impl.AetherResolveSession.getRemotes(aether.kt:52)
       at kotlin.script.experimental.dependencies.maven.impl.AetherResolveSession.request(aether.kt:177)
       at kotlin.script.experimental.dependencies.maven.impl.AetherResolveSession.resolveDependencies(aether.kt:138)
       at kotlin.script.experimental.dependencies.maven.impl.AetherResolveSession.resolve(aether.kt:131)
       at kotlin.script.experimental.dependencies.maven.MavenDependenciesResolver.resolve(MavenDependenciesResolver.kt:69)
       at kotlin.script.experimental.dependencies.CompoundDependenciesResolver.resolve(CompoundDependenciesResolver.kt:68)
       at kotlin.script.experimental.dependencies.AnnotationsKt.resolveFromScriptSourceAnnotations(annotations.kt:70)
       at org.jetbrains.kotlin.mainKts.MainKtsConfigurator$processAnnotations$resolveResult$1.invokeSuspend(scriptDef.kt:201)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlin.coroutines.ContinuationKt.startCoroutine(Continuation.kt:115)

The exception occurs when I click on jvm/main-kts/scripts/kotlin-shell.main.kts in Idea.
I also noticed some warnings like this:


WARN - #o.j.k.i.script - [KOTLIN_SCRIPTING] Script configuration for file file:///.../kotlin-script-examples/jvm/main-kts/scripts/kotlin-shell.main.kts was not loaded

I am able to run the scripts, however Idea does not highlight errors or understand the types or support navigating to the definitions found in the scripts. 
I'm looking for an example of using custom scripts in a way that allows navigating the scripts with Idea in the usual way.

0
2 comments

I was able to get Idea to recognize the dependencies for the *.simplescript.kts files by adding en empty file named

jvm/basic/jvm-simple-script/script/src/main/resources/META-INF/kotlin/script/templates/org.jetbrains.kotlin.script.examples.jvm.simple.SimpleScript.classname

after invalidating caches, restarting Idea and rebuilding the project. The same method did not work for the example with maven dependencies and the Idea log showed these errors:

2022-05-02 13:41:14,165 [ 109271] SEVERE - #o.j.k.i.script - [KOTLIN_SCRIPTING] Cannot load script definition class org.jetbrains.kotlin.script.examples.jvm.resolve.maven.ScriptWithMavenDeps 
java.lang.ExceptionInInitializerError
       at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)
       at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unsafe.java:1042)
       at java.base/jdk.internal.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
       at java.base/jdk.internal.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:186)
       at java.base/java.lang.reflect.Field.acquireFieldAccessor(Field.java:1105)
       at java.base/java.lang.reflect.Field.getFieldAccessor(Field.java:1086)
       at java.base/java.lang.reflect.Field.get(Field.java:418)
       at kotlin.reflect.jvm.internal.KClassImpl$Data$objectInstance$2.invoke(KClassImpl.kt:117)
       at kotlin.reflect.jvm.internal.ReflectProperties$LazyVal.invoke(ReflectProperties.java:63)
       at kotlin.reflect.jvm.internal.ReflectProperties$Val.getValue(ReflectProperties.java:32)
       at kotlin.reflect.jvm.internal.KClassImpl$Data.getObjectInstance(KClassImpl.kt:108)
       at kotlin.reflect.jvm.internal.KClassImpl.getObjectInstance(KClassImpl.kt:242)
       at kotlin.script.experimental.host.ConfigurationFromTemplateKt.constructCompilationConfiguration(configurationFromTemplate.kt:199)
       at kotlin.script.experimental.host.ConfigurationFromTemplateKt.createScriptDefinitionFromTemplate(configurationFromTemplate.kt:42)
       at kotlin.script.experimental.host.ConfigurationFromTemplateKt.createScriptDefinitionFromTemplate$default(configurationFromTemplate.kt:29)
       at org.jetbrains.kotlin.scripting.definitions.ScriptDefinition$FromTemplate.<init>(ScriptDefinition.kt:213)
       at org.jetbrains.kotlin.idea.core.script.ScriptDefinitionsManagerKt.loadDefinitionsFromTemplatesByPaths(ScriptDefinitionsManager.kt:367)
       at org.jetbrains.kotlin.idea.core.script.ScriptDefinitionsManagerKt.loadDefinitionsFromTemplatesByPaths$default(ScriptDefinitionsManager.kt:340)
       at org.jetbrains.kotlin.idea.script.ScriptTemplatesFromDependenciesProvider$loadScriptDefinitions$task$1.run(ScriptTemplatesFromDependenciesProvider.kt:145)
       at com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:442)
       at com.intellij.openapi.progress.impl.ProgressManagerImpl.startTask(ProgressManagerImpl.java:114)
       at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressAsynchronously$5(CoreProgressManager.java:493)
       at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$3(ProgressRunner.java:244)
       at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:189)
       at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$12(CoreProgressManager.java:608)
       at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:683)
       at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:639)
       at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:607)
       at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
       at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:176)
       at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:244)
       at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
       at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
       at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
       at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
       at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
       at java.base/java.security.AccessController.doPrivileged(Native Method)
       at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
       at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: kotlin.script.experimental.jvm.util.ClasspathExtractionException: Unable to get script compilation classpath from context, please specify explicit classpath via "kotlin.script.classpath" property
       at kotlin.script.experimental.jvm.util.JvmClasspathUtilKt.scriptCompilationClasspathFromContext(jvmClasspathUtil.kt:345)
       at kotlin.script.experimental.jvm.JvmScriptCompilationKt.dependenciesFromClassloader(jvmScriptCompilation.kt:57)
       at kotlin.script.experimental.jvm.JvmScriptCompilationKt.dependenciesFromClassloader$default(jvmScriptCompilation.kt:50)
       at kotlin.script.experimental.jvm.JvmScriptCompilationKt.dependenciesFromCurrentContext(jvmScriptCompilation.kt:47)
       at kotlin.script.experimental.jvm.JvmScriptCompilationKt.dependenciesFromCurrentContext$default(jvmScriptCompilation.kt:42)
       at org.jetbrains.kotlin.script.examples.jvm.resolve.maven.ScriptWithMavenDepsConfiguration$1$1.invoke(scriptDef.kt:42)
       at org.jetbrains.kotlin.script.examples.jvm.resolve.maven.ScriptWithMavenDepsConfiguration$1$1.invoke(scriptDef.kt:37)
       at kotlin.script.experimental.util.PropertiesCollection$Builder.invoke(propertiesCollection.kt:282)
       at org.jetbrains.kotlin.script.examples.jvm.resolve.maven.ScriptWithMavenDepsConfiguration$1.invoke(scriptDef.kt:37)
       at org.jetbrains.kotlin.script.examples.jvm.resolve.maven.ScriptWithMavenDepsConfiguration$1.invoke(scriptDef.kt:32)
       at kotlin.script.experimental.api.ScriptCompilationConfiguration.<init>(scriptCompilation.kt:23)
       at kotlin.script.experimental.api.ScriptCompilationConfiguration.<init>(scriptCompilation.kt:25)
       at org.jetbrains.kotlin.script.examples.jvm.resolve.maven.ScriptWithMavenDepsConfiguration.<init>(scriptDef.kt:31)
       at org.jetbrains.kotlin.script.examples.jvm.resolve.maven.ScriptWithMavenDepsConfiguration.<clinit>(scriptDef.kt)
       ... 39 more
2022-05-02 13:41:14,169 [ 109275] SEVERE - #o.j.k.i.script - IntelliJ IDEA 2022.1  Build #IU-221.5080.210
2022-05-02 13:41:14,169 [ 109275] SEVERE - #o.j.k.i.script - JDK: 11.0.14.1; VM: OpenJDK 64-Bit Server VM; Vendor: JetBrains s.r.o.
2022-05-02 13:41:14,170 [ 109276] SEVERE - #o.j.k.i.script - OS: Linux
2022-05-02 13:41:14,176 [ 109282] SEVERE - #o.j.k.i.script - Plugin to blame: Kotlin version: 221-1.6.20-release-285-IJ5080.210

0

Please, file an issue and attach your idea.log. Thank you!

0

Please sign in to leave a comment.