java.lang.reflect.InaccessibleObjectException: Unable to make field private transient java.lang.Object java.lang.Throwable.backtrace accessible: module java.base does not "opens java.lang" to unnamed module @76628072

See original GitHub issue

Expected Behavior

The task should tell me if there is a problem with the code style or not.

Observed Behavior

Crash:

> Task :ktlintFormat FAILED
17:02:10.989 [main] DEBUG com.pinterest.ktlint.Main - Discovered reporter with "baseline" id.
17:02:10.989 [main] DEBUG com.pinterest.ktlint.Main - Discovered reporter with "checkstyle" id.
17:02:10.990 [main] DEBUG com.pinterest.ktlint.Main - Discovered reporter with "json" id.
17:02:10.990 [main] DEBUG com.pinterest.ktlint.Main - Discovered reporter with "html" id.
17:02:10.990 [main] DEBUG com.pinterest.ktlint.Main - Discovered reporter with "plain" id.
17:02:10.990 [main] DEBUG com.pinterest.ktlint.Main - Discovered reporter with "sarif" id.
17:02:10.990 [main] DEBUG com.pinterest.ktlint.Main - Initializing "plain" reporter with {verbose=false, color=false, color_name=DARK_GRAY}
Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.ExceptionInInitializerError
        at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
        at com.pinterest.ktlint.KtlintCommandLine.parallel(Main.kt:606)
        at com.pinterest.ktlint.KtlintCommandLine.parallel$default(Main.kt:578)
        at com.pinterest.ktlint.KtlintCommandLine.lintFiles(Main.kt:321)
        at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:282)
        at com.pinterest.ktlint.Main.main(Main.kt:76)
Caused by: java.lang.ExceptionInInitializerError
        at org.jetbrains.kotlin.com.intellij.util.exception.FrequentErrorLogger.report(FrequentErrorLogger.java:47)
        at org.jetbrains.kotlin.com.intellij.util.exception.FrequentErrorLogger.info(FrequentErrorLogger.java:43)
        at org.jetbrains.kotlin.com.intellij.psi.impl.DebugUtil.handleUnspecifiedTrace(DebugUtil.java:628)
        at org.jetbrains.kotlin.com.intellij.psi.impl.DebugUtil.currentInvalidationTrace(DebugUtil.java:620)
        at org.jetbrains.kotlin.com.intellij.psi.impl.DebugUtil.calcInvalidationTrace(DebugUtil.java:614)
        at org.jetbrains.kotlin.com.intellij.psi.impl.DebugUtil.onInvalidated(DebugUtil.java:585)
        at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.TreeElement.onInvalidated(TreeElement.java:226)
        at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.TreeElement.rawRemoveUpToWithoutNotifications(TreeElement.java:388)
        at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.TreeElement.rawRemoveUpTo(TreeElement.java:342)
        at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.CompositeElement.remove(CompositeElement.java:775)
        at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.CompositeElement.lambda$removeChildrenInner$4(CompositeElement.java:797)
        at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.ChangeUtil$1.runInner(ChangeUtil.java:147)
        at org.jetbrains.kotlin.com.intellij.pom.impl.PomTransactionBase.run(PomTransactionBase.java:28)
        at com.pinterest.ktlint.core.internal.FormatPomModel.runTransaction(KotlinPsiFileFactory.kt:121)
        at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.ChangeUtil.prepareAndRunChangeAction(ChangeUtil.java:142)
        at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.CompositeElement.removeChildrenInner(CompositeElement.java:796)
        at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.CompositeElement.removeRange(CompositeElement.java:611)
        at com.pinterest.ktlint.ruleset.standard.ImportOrderingRule.visit(ImportOrderingRule.kt:235)
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:351)
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:344)
        at com.pinterest.ktlint.core.VisitorProvider$sequentialVisitor$1$1$1$1.invoke(VisitorProvider.kt:102)
        at com.pinterest.ktlint.core.VisitorProvider$sequentialVisitor$1$1$1$1.invoke(VisitorProvider.kt:102)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:229)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:230)
        at com.pinterest.ktlint.core.VisitorProvider$sequentialVisitor$1.invoke(VisitorProvider.kt:102)
        at com.pinterest.ktlint.core.VisitorProvider$sequentialVisitor$1.invoke(VisitorProvider.kt:94)
        at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:344)
        at com.pinterest.ktlint.internal.FileUtilsKt.formatFile(FileUtils.kt:221)
        at com.pinterest.ktlint.KtlintCommandLine.process(Main.kt:396)
        at com.pinterest.ktlint.KtlintCommandLine.access$process(Main.kt:95)
        at com.pinterest.ktlint.KtlintCommandLine$lintFiles$3.invoke$lambda-1(Main.kt:311)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private transient java.lang.Object java.lang.Throwable.backtrace accessible: module java.base does not "opens java.lang" to unnamed module @76628072
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
        at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
        at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
        at org.jetbrains.kotlin.com.intellij.util.ReflectionUtil.findFieldInHierarchy(ReflectionUtil.java:154)
        at org.jetbrains.kotlin.com.intellij.util.ReflectionUtil.getDeclaredField(ReflectionUtil.java:279)
        at org.jetbrains.kotlin.com.intellij.openapi.util.objectTree.ThrowableInterner.<clinit>(ThrowableInterner.java:88)
        ... 35 more

FAILURE: Build failed with an exception.

Steps to Reproduce

ktlint.gradle:

apply plugin: 'java'

repositories {
    mavenCentral()
}

configurations {
    ktlint
}

dependencies {
    ktlint("com.pinterest:ktlint:0.44.0") {
        attributes {
            attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
        }
    }
    // additional 3rd party ruleset(s) can be specified here
    // just add them to the classpath (e.g. ktlint 'groupId:artifactId:version') and
    // ktlint will pick them up
}

task ktlint(type: JavaExec, group: "verification") {
    description = "Check Kotlin code style."
    classpath = configurations.ktlint
    mainClass.set("com.pinterest.ktlint.Main")
    args "-F", "**/src/**/*.kt", "!**/genMain/**", "!**/genTest/**"
    // to generate report in checkstyle format prepend following args:
    // "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/ktlint.xml"
    // to add a baseline to check against prepend following args:
    // "--baseline=ktlint-baseline.xml"
    // see https://github.com/pinterest/ktlint#usage for more
}
check.dependsOn ktlint

task ktlintFormat(type: JavaExec, group: "formatting") {
    description = "Fix Kotlin code style deviations."
    classpath = configurations.ktlint
    mainClass.set("com.pinterest.ktlint.Main")
    args "-F", "**/src/**/*.kt", "!**/genMain/**", "!**/genTest/**"
}

Your Environment

  • Version of ktlint used: 0.44.0
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task):
  • Version of Gradle used (if applicable): 7.4
  • Operating System and version: Latest MacOS Monterey
  • Link to your project (if it’s a public repository): https://github.com/ScottPierce/kotlin-html/tree/scott/Kotlin_1_6
  • Java Version:
java --version        
openjdk 17.0.2 2022-01-18 LTS
OpenJDK Runtime Environment Corretto-17.0.2.8.1 (build 17.0.2+8-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.2.8.1 (build 17.0.2+8-LTS, mixed mode, sharing)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:25

github_iconTop GitHub Comments

5reactions
paul-dingemanscommented, Sep 19, 2022

Sorry, I was just running the ktlint CLI version which worked fine. Tnx for pointing once more to ./gradlew ktlintFormat which does reproduce the problem. Based on @cwilper’s comment, I got it working by changing the definition of the ktlintFormat task as follows:

val ktlintFormat by tasks.creating(JavaExec::class) {
    inputs.files(inputFiles)
    outputs.dir(outputDir)

    description = "Fix Kotlin code style deviations."
    classpath = ktlint
    jvmArgs = listOf("--add-opens=java.base/java.lang=ALL-UNNAMED")
    setProperty("mainClass", "com.pinterest.ktlint.Main")
    args = listOf("-F", "src/**/*.kt")
}
1reaction
paul-dingemanscommented, Dec 3, 2022

I am not sure whether OP’s original problem is solved, but I am loosing track on the status of this issue.

The problem is caused by newer Java version restricting access to certain libraries. We have to wait until libraries we use, do solve this problem so that it does not propagate via KtLint. Providing the --add-opens=java.base/java.lang=ALL-UNNAMED in one of ways suggested before is the way to go for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to make field private final java.util ... - Stack Overflow
I solved my problem. Turns out the JRE that eclipse had automatically downloaded and was using wasn't compatible with this version of ...
Read more >
An illegal reflective access operation has occurred ...
InaccessibleObjectException : Unable to make field private transient java.lang.Object java.lang.Throwable.backtrace accessible: module java.base does not ...
Read more >
unable to make field private transient java.lang ... - You.com
Object java.lang.Throwable.backtrace accessible: module java.base does not "opens java.lang" to unnamed module @76628072 java.lang.reflect.
Read more >
Unable to make field transient java.lang.Object[] java.util ...
Object [] java.util.ArrayList.elementData accessible: module java.base does not "opens java.util" to unnamed module @3bf44630.
Read more >
Can't Run Javafx Application with Jfoenix Lib - ADocLib
reflect.InaccessibleObjectException: Unable to make field private transient java.lang.Object java.lang.Throwable.backtrace accessible: module java.base does ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found