kiddagger
kiddagger

Reputation: 341

Java.lang.ExceptionInInitializerError when running Kotlin REPL in Intellij

I have a brand new install of Intellij 2020.3.3 Community and JDK v16. I booted up Intellij, and made sure to update the Kotlin plugin. I created a new Kotlin project, and have made no changes to it. I attempted to run the Kotlin REPL tool (Tools->Kotlin->Kotlin REPL) and I get the following exception:

"C:\Program Files\Java\jdk-16\bin\java.exe" -Dkotlin.repl.ideMode=true -Dfile.encoding=UTF-8     @C:\Users\---\AppData\Local\Temp\idea_arg_file349852720
exception: java.lang.ExceptionInInitializerError
    at com.intellij.pom.java.LanguageLevel.<clinit>(LanguageLevel.java:25)
    at com.intellij.core.CoreLanguageLevelProjectExtension.<init>    (CoreLanguageLevelProjectExtension.java:26)
    at com.intellij.core.JavaCoreProjectEnvironment.<init>(JavaCoreProjectEnvironment.java:42)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreProjectEnvironment.<init>    (KotlinCoreProjectEnvironment.kt:26)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$ProjectEnvironment.<init>    (KotlinCoreEnvironment.kt:121)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:90)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:88)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:76)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:45)
    at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMainNoExit(CLITool.kt:227)
    at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMainNoExit$default(CLITool.kt:222)
    at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMain(CLITool.kt:214)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler$Companion.main(K2JVMCompiler.kt:271)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.main(K2JVMCompiler.kt)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected void     java.util.ResourceBundle.setParent(java.util.ResourceBundle) accessible: module java.base does not "opens     java.util" to unnamed module @55141def
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
    at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
    at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
    at com.intellij.util.ReflectionUtil.makeAccessible(ReflectionUtil.java:252)
    at com.intellij.util.ReflectionUtil.getDeclaredMethod(ReflectionUtil.java:269)
    at com.intellij.DynamicBundle.<clinit>(DynamicBundle.java:22)
    ... 17 more

I have attempted to reinstall the JDK/IDE, and cleared the temp folder. Not sure what else to try, both the IDE and language are new to me. Suggestions?

EDIT

Found workaround: I did another uninstall, and downgraded to JDKv8 and the issue isn't present.

Upvotes: 12

Views: 13300

Answers (7)

aquilesb
aquilesb

Reputation: 2262

It has been a long time since this question was posted but as I can see no final answers were posted, I will give my 2 cents for how I solved the issue.

I solved my problem by adding the Java JVM arguments:

-add-opens java.base/java.util=ALL-UNNAMED

Be aware, that there are multiple Java packages where this can happen, and you can solve all them adding multiple JVM arguments by only changing the Java package.

Upvotes: 0

sam
sam

Reputation: 16

settings -> editor -> plugins -> update kotlin plugin

Upvotes: 0

Ahmad Aghazadeh
Ahmad Aghazadeh

Reputation: 17131

In this case, all of the compileOptions, the kotlinOptions, and the GradleJdk have the same version. Like the below picture.

enter image description here

Upvotes: 2

Uday
Uday

Reputation: 71

I installed IntelliJ IDEA Community Edition 2021.1.3 today and am using JDK-16.0.1 on my linux PC.

This also happened in my case. I went through all the settings at first then I found that I had a Kotlin update. After my update the Kotlin REPL started without any error.

To update the Kotlin plugin go to Settings -> Languages & Frameworks -> Kotlin.

Click the check again button to know if you have any new update. If so, then update it and restart, then see if Kotlin REPL is working or not.

Upvotes: 4

Krutin
Krutin

Reputation: 1

I downloaded adoptopenjdk version 1.8 after creating a new project, and the issue was resolved

Upvotes: 0

Alexis Andrade
Alexis Andrade

Reputation: 76

I fixed it by using JDK 15 instead of 16.

To use JDK 15 follow these steps:

File -> New -> Project...

-> In «Project SDK» go to «Download JDK» and choose «Version: 15» and click Download.

Then just create your project as always (using JDK 15 following the previous steps).

Upvotes: 3

Ahmed Lotfy
Ahmed Lotfy

Reputation: 1145

I had the same issue during Java upgrades. i use AdoptOpenJDK 16.0.0.j9-adpt and i fixed it by:

  • Upgrade Gradle version to 7.0-rc-1 (i'm early testing it with Java 16)

  • Updated my Gradle script with the below section:

    compileKotlin {
       kotlinOptions {
          jvmTarget = "15"
       }
    }
    
    compileTestKotlin {
       kotlinOptions {
          jvmTarget = "15"
       }
    }
    

Java 16 still not supported yet in the Enum so i had to place it to 15 for now.

Upvotes: 1

Related Questions