Maven + OpenJDK16 + Kotlin 1.4.31 or 1.5.0-M1 llegalAccessException

Tried with 1.4.31 and 1.5.0-M1, both give the same error, unable to compile project using OpenJDK16.
$ java -fullversion
openjdk full version “16+36-2231”
$ mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /home/user/.sdkman/candidates/maven/current
Java version: 16, vendor: Oracle Corporation, runtime: /home/user/.sdkman/candidates/java/16-open
Default locale: en_US, platform encoding: UTF-8
OS name: “linux”, version: “5.8.0-45-generic”, arch: “amd64”, family: “unix”
$ free -h
total used free shared buff/cache available
Mem: 31Gi 11Gi 308Mi 519Mi 19Gi 18Gi
Swap: 2.0Gi 4.0Mi 2.0Gi

Here is the output of 1.5.0-M1, the same is with 1.4.31 so not adding that here.

[INFO] --- kotlin-maven-plugin:1.5.0-M1:compile (compile) @ xxx ---
[WARNING] Using experimental Kotlin incremental compilation
ERROR: symbolic reference class is not accessible: class sun.nio.ch.FileChannelImpl, from class com.intellij.util.io.FileChannelUtil (unnamed module @7645b7d)
java.lang.IllegalAccessException: symbolic reference class is not accessible: class sun.nio.ch.FileChannelImpl, from class com.intellij.util.io.FileChannelUtil (unnamed module @7645b7d)
        at java.base/java.lang.invoke.MemberName.makeAccessException(MemberName.java:957)
        at java.base/java.lang.invoke.MethodHandles$Lookup.checkSymbolicClass(MethodHandles.java:3675)
        at java.base/java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:3647)
        at java.base/java.lang.invoke.MethodHandles$Lookup.findVirtual(MethodHandles.java:2687)
        at com.intellij.util.io.FileChannelUtil.setupUnInterruptibleHandle(FileChannelUtil.java:36)
        at com.intellij.util.io.FileChannelUtil.<clinit>(FileChannelUtil.java:18)
        at com.intellij.util.io.ReadWriteDirectBufferWrapper$FileContext$1.execute(ReadWriteDirectBufferWrapper.java:59)
        at com.intellij.util.io.ReadWriteDirectBufferWrapper$FileContext$1.execute(ReadWriteDirectBufferWrapper.java:49)
        at com.intellij.openapi.util.io.FileUtilRt.doIOOperation(FileUtilRt.java:957)
        at com.intellij.util.io.ReadWriteDirectBufferWrapper$FileContext.<init>(ReadWriteDirectBufferWrapper.java:49)
        at com.intellij.util.io.ReadWriteDirectBufferWrapper.create(ReadWriteDirectBufferWrapper.java:35)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
        at java.base/java.lang.Thread.run(Thread.java:831)
[INFO] Rebuilding because of possible caches corruption: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.AssertionError: symbolic reference class is not accessible: class sun.nio.ch.FileChannelImpl, from class com.intellij.util.io.FileChannelUtil (unnamed module @7645b7d)
[INFO] Non-incremental compilation will be performed: CACHE_CORRUPTION
java.io.IOException: Could not delete internal caches in folder /media/user/projects/xxx/target/kotlin-ic/compile
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.clearLocalStateOnRebuild(IncrementalCompilerRunner.kt:167)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:139)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:74)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile$default(IncrementalCompilerRunner.kt:65)
        at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunnerKt.makeIncrementally(IncrementalJvmCompilerRunner.kt:84)
        at org.jetbrains.kotlin.maven.K2JVMCompileMojo.runIncrementalCompiler(K2JVMCompileMojo.java:270)
        at org.jetbrains.kotlin.maven.K2JVMCompileMojo.execCompiler(K2JVMCompileMojo.java:234)
        at org.jetbrains.kotlin.maven.K2JVMCompileMojo.execCompiler(K2JVMCompileMojo.java:55)
        at org.jetbrains.kotlin.maven.KotlinCompileMojoBase.execute(KotlinCompileMojoBase.java:209)
        at org.jetbrains.kotlin.maven.K2JVMCompileMojo.execute(K2JVMCompileMojo.java:222)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)

Looks like Kotlin compiler doesn’t support JDK 16 yet, see https://youtrack.jetbrains.com/issue/KT-45566.

Looks like it’s fixed in M2:

https://youtrack.jetbrains.com/issue/KT-45566#focus=Comments-27-4781545.0-0

will kotln intellij plugin needs to be updated or as long as mvn dependency is updated to m2 it will work?

I’m not 100% sure but I guess that only the maven dependency will need to be updated.

@jeka_1980 you can consider to compile with JDK 15 and run with JDK 16 as a temporary workaround.