java.lang.IllegalAccessError: class org.jetbrains.kotlin.kapt3.base.KaptContext (in unnamed module @0x211b5d9) cannot access class com.sun.tools.javac.util.Context (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.util to unnamed module @0x211b5d9
at org.jetbrains.kotlin.kapt3.base.KaptContext.(KaptContext.kt:28)
at org.jetbrains.kotlin.kapt3.KaptContextForStubGeneration.(KaptContextForStubGeneration.kt:40)
at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.contextForStubGeneration(Kapt3Extension.kt:287)
at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:171)
at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:102)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationdefault(TopDownAnalyzerFacadeForJVM.kt:86)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler1.invoke(KotlinToJVMBytecodeCompiler.kt:252)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler1.invoke(KotlinToJVMBytecodeCompiler.kt:243)
at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:113)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:243)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModulesclidefault(IncrementalCompilerRunner.kt:300)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImplexecIncrementalCompiler(CompileServiceImpl.kt:96)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1658)
Assistant
The error you're encountering is a result of a module access control implemented by the Java Platform Module System (JPMS), introduced in Java 9. The issue occurs because the jdk.compiler module does not export the com.sun.tools.javac.util package to the unnamed module where is located. This leads to the during the Kotlin annotation processing (kapt).
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Upgrade Your Tools: First, ensure you're using the latest version of Kotlin and your build tools (like Gradle or Maven). Compatibility issues like this are often resolved in newer versions of the tools.
Add JVM Arguments: You can explicitly open the jdk.compiler module to all unnamed modules by adding JVM arguments to your build script or IDE configuration. For Gradle, you can add the following to the gradle.properties file or configure the JAVA_OPTS environment variable:
Use Kotlin's JVM Target Compatibility Options: If you're using Kotlin, ensure your kotlinOptions in your Gradle file are configured to target a compatible JVM version. Sometimes targeting an older version helps avoid such issues:
Note that adjusting the target JVM version is more of a workaround than a solution and might not solve all issues related to JPMS.
Remember, while opening packages to unnamed modules via JVM arguments can resolve your immediate issue, it might not be the best long-term solution from a modularity and security perspective. Always strive to keep your tools up-to-date and follow the best practices recommended by tool and library authors.