Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ktlint fails on Java 16+ #1195

Closed
itsandreramon opened this issue Aug 5, 2021 · 29 comments · Fixed by #1359
Closed

ktlint fails on Java 16+ #1195

itsandreramon opened this issue Aug 5, 2021 · 29 comments · Fixed by #1359
Assignees
Labels

Comments

@itsandreramon
Copy link

Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: Could not initialize class org.jetbrains.kotlin.com.intellij.pom.java.LanguageLevel
        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:575)
        at com.pinterest.ktlint.KtlintCommandLine.parallel$default(Main.kt:547)
        at com.pinterest.ktlint.KtlintCommandLine.lintFiles(Main.kt:298)
        at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:262)
        at com.pinterest.ktlint.Main.main(Main.kt:70)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.jetbrains.kotlin.com.intellij.pom.java.LanguageLevel
        at org.jetbrains.kotlin.com.intellij.core.CoreLanguageLevelProjectExtension.<init>(CoreLanguageLevelProjectExtension.java:26)
        at org.jetbrains.kotlin.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.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:425)
        at com.pinterest.ktlint.core.internal.KotlinPsiFileFactory.initializePsiFileFactory(KotlinPsiFileFactory.kt:74)
        at com.pinterest.ktlint.core.internal.KotlinPsiFileFactory.acquirePsiFileFactory$ktlint_core(KotlinPsiFileFactory.kt:39)
        at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:378)
        at com.pinterest.ktlint.internal.FileUtilsKt.formatFile(FileUtils.kt:182)
        at com.pinterest.ktlint.KtlintCommandLine.process(Main.kt:366)
        at com.pinterest.ktlint.KtlintCommandLine.access$process(Main.kt:89)
        at com.pinterest.ktlint.KtlintCommandLine$lintFiles$3$1.call(Main.kt:289)
        at com.pinterest.ktlint.KtlintCommandLine$lintFiles$3$1.call(Main.kt:288)
        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)
@romtsn
Copy link
Collaborator

romtsn commented Aug 8, 2021

Are you using cli or a gradle plugin? For me, this looks like you are using either an older version of ktlint or having an older version of Kotlin (< 1.5.0), which substitutes ktlint's Kotlin version, because the issue has been resolved in Kotlin 1.5.0-M2 it looks like (and we are targeting 1.5.20 in the latest release)

@Gama11
Copy link

Gama11 commented Aug 9, 2021

To me this happens with the CLI version.

@itsandreramon
Copy link
Author

itsandreramon commented Aug 9, 2021

I am using ktlint with Gradle wrapper (without a plugin) with Gradle 7.1.1
I upgraded to Kotlin 1.5.21 and ktlint 0.42.1 now, but get this error now instead:

when running ./gradlew ktlintFormat:

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:575)
        at com.pinterest.ktlint.KtlintCommandLine.parallel$default(Main.kt:547)
        at com.pinterest.ktlint.KtlintCommandLine.lintFiles(Main.kt:298)
        at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:262)
        at com.pinterest.ktlint.Main.main(Main.kt:70)
Caused by: java.lang.ExceptionInInitializerError
        at org.jetbrains.kotlin.com.intellij.util.exception.FrequentErrorLogger.report(FrequentErrorLogger.java:46)
        at org.jetbrains.kotlin.com.intellij.util.exception.FrequentErrorLogger.info(FrequentErrorLogger.java:42)
        at org.jetbrains.kotlin.com.intellij.psi.impl.DebugUtil.handleUnspecifiedTrace(DebugUtil.java:626)
        at org.jetbrains.kotlin.com.intellij.psi.impl.DebugUtil.currentInvalidationTrace(DebugUtil.java:618)
        at org.jetbrains.kotlin.com.intellij.psi.impl.DebugUtil.calcInvalidationTrace(DebugUtil.java:612)
        at org.jetbrains.kotlin.com.intellij.psi.impl.DebugUtil.onInvalidated(DebugUtil.java:583)
        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.invalidate(TreeElement.java:328)
        at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.TreeElement.rawRemove(TreeElement.java:312)
        at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.TreeElement.rawReplaceWithList(TreeElement.java:319)
        at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafElement.rawReplaceWithText(LeafElement.java:146)
        at com.pinterest.ktlint.ruleset.standard.IndentationRule.visitWhiteSpace(IndentationRule.kt:1083)
        at com.pinterest.ktlint.ruleset.standard.IndentationRule.access$visitWhiteSpace(IndentationRule.kt:103)
        at com.pinterest.ktlint.ruleset.standard.IndentationRule$indent$2.invoke(IndentationRule.kt:600)
        at com.pinterest.ktlint.ruleset.standard.IndentationRule$indent$2.invoke(IndentationRule.kt:463)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:230)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:231)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:231)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:231)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:231)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:231)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:231)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:231)
        at com.pinterest.ktlint.ruleset.standard.IndentationRule.indent(IndentationRule.kt:462)
        at com.pinterest.ktlint.ruleset.standard.IndentationRule.visit(IndentationRule.kt:162)
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:391)
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:384)
        at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:320)
        at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:302)
        at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:384)
        at com.pinterest.ktlint.internal.FileUtilsKt.formatFile(FileUtils.kt:199)
        at com.pinterest.ktlint.KtlintCommandLine.process(Main.kt:366)
        at com.pinterest.ktlint.KtlintCommandLine.access$process(Main.kt:89)
        at com.pinterest.ktlint.KtlintCommandLine$lintFiles$3.invoke$lambda-0(Main.kt:289)
        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)
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 @7c29daf3
        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.Field.checkCanSetAccessible(Field.java:177)
        at java.base/java.lang.reflect.Field.setAccessible(Field.java:171)
        at org.jetbrains.kotlin.com.intellij.util.ReflectionUtil.findFieldInHierarchy(ReflectionUtil.java:153)
        at org.jetbrains.kotlin.com.intellij.util.ReflectionUtil.getDeclaredField(ReflectionUtil.java:278)
        at org.jetbrains.kotlin.com.intellij.openapi.util.objectTree.ThrowableInterner.<clinit>(ThrowableInterner.java:81)
        ... 38 more

@Tapchicoma Tapchicoma added the bug label Aug 9, 2021
@mikko-apo
Copy link

I am using ktlint with Gradle wrapper (without a plugin) with Gradle 7.1.1
I upgraded to Kotlin 1.5.21 and ktlint 0.42.1 now, but get this error now instead:

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 @7c29daf3

I have the same version combination and the same failure happens.

@Tapchicoma
Copy link
Collaborator

hm, probably we also need to add --add-opens to KtLint CLI/README. Will take a look into it.

@Tapchicoma
Copy link
Collaborator

You could try to run KtLint with --add-opens "java.base/java.util=ALL-UNNAMED" --add-exports="java.base/sun.nio.ch=ALL-UNNAMED" arguments.

@itsandreramon
Copy link
Author

itsandreramon commented Aug 14, 2021

It seems to work for me after adding this line as stated in the new readme for 0.42.1:

attributes {
    attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
}

Edit: Not working again now
I changed the main = "..." to mainClass = "..." and get this error now:

Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: Could not initialize class org.jetbrains.kotlin.com.intellij.openapi.util.objectTree.ThrowableInterner
        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:575)
        at com.pinterest.ktlint.KtlintCommandLine.parallel$default(Main.kt:547)
        at com.pinterest.ktlint.KtlintCommandLine.lintFiles(Main.kt:298)
        at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:262)
        at com.pinterest.ktlint.Main.main(Main.kt:70)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.jetbrains.kotlin.com.intellij.openapi.util.objectTree.ThrowableInterner
        at org.jetbrains.kotlin.com.intellij.util.exception.FrequentErrorLogger.report(FrequentErrorLogger.java:46)
        at org.jetbrains.kotlin.com.intellij.util.exception.FrequentErrorLogger.info(FrequentErrorLogger.java:42)
        at org.jetbrains.kotlin.com.intellij.psi.impl.DebugUtil.handleUnspecifiedTrace(DebugUtil.java:626)
        at org.jetbrains.kotlin.com.intellij.psi.impl.DebugUtil.currentInvalidationTrace(DebugUtil.java:618)
        at org.jetbrains.kotlin.com.intellij.psi.impl.DebugUtil.calcInvalidationTrace(DebugUtil.java:612)
        at org.jetbrains.kotlin.com.intellij.psi.impl.DebugUtil.onInvalidated(DebugUtil.java:583)
        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:149)
        at org.jetbrains.kotlin.com.intellij.pom.impl.PomTransactionBase.run(PomTransactionBase.java:46)
        at com.pinterest.ktlint.core.internal.KotlinPsiFileFactory$FormatPomModel.runTransaction(KotlinPsiFileFactory.kt:140)
        at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.ChangeUtil.prepareAndRunChangeAction(ChangeUtil.java:143)
        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.removeChildInner(CompositeElement.java:790)
        at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.CompositeElement.removeChild(CompositeElement.java:606)
        at com.pinterest.ktlint.ruleset.standard.SpacingAroundColonRule.visit(SpacingAroundColonRule.kt:94)
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:391)
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:384)
        at com.pinterest.ktlint.core.KtLint$visitor$2$2.invoke(KtLint.kt:315)
        at com.pinterest.ktlint.core.KtLint$visitor$2$2.invoke(KtLint.kt:314)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:225)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:314)
        at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:302)
        at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:384)
        at com.pinterest.ktlint.internal.FileUtilsKt.formatFile(FileUtils.kt:199)
        at com.pinterest.ktlint.KtlintCommandLine.process(Main.kt:366)
        at com.pinterest.ktlint.KtlintCommandLine.access$process(Main.kt:89)
        at com.pinterest.ktlint.KtlintCommandLine$lintFiles$3.invoke$lambda-0(Main.kt:289)
        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)

@cuichanghao
Copy link

Android Studio Arctic Fox with java 11、the same problem.

@massivemadness
Copy link

Any news about this?

@itsandreramon itsandreramon changed the title ktlint fails on Java 16 ktlint fails on Java 16+ Oct 3, 2021
@itsandreramon
Copy link
Author

@cuichanghao could you make sure everything is setup correctly? java 11 should work fine, I'm using Java 11 right now due to this issue

@tekener
Copy link

tekener commented Dec 3, 2021

For maven projects using the maven-antrun-plugin you can add this to your pom:

<java taskname="ktlint" dir="${basedir}" fork="true" failonerror="true" classname="com.pinterest.ktlint.Main" classpathref="maven.plugin.classpath">
      <jvmarg value="--add-opens"/>
      <jvmarg value="java.base/java.lang=ALL-UNNAMED"/>

@kirillgroshkov
Copy link

happens to us too

@xzhang-brex
Copy link

same here

@itsandreramon
Copy link
Author

@Tapchicoma @shashachu @shyiko any timeline on fixing this?

@itsandreramon
Copy link
Author

itsandreramon commented Jan 4, 2022

I am currently trying to fix it myself. I cloned the repo and built a jar with Java 17 on my own machine. I ran it with the following configuration, which seems to work:

java --add-opens java.base/java.lang=ALL-UNNAMED -jar ktlint-0.44.0-SNAPSHOT-all.jar -F "*/**/*.kt"

All tests passed, 3 were skipped.

@tcrawford-figure
Copy link
Contributor

For those using the Gradle Kotlin DSL, I was able to invoke the formatter without issues with JDK 17 by doing the following:

tasks.register<JavaExec>("ktlintFormat") {
    group = "formatting"
    description = "Fix Kotlin code style deviations"
    classpath = ktlint
    mainClass.set("com.pinterest.ktlint.Main")
    args("-F", "src/**/*.kt")
    jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
}

The most important part here is adding:

jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")

@AmitTGTG
Copy link

The most important part here is adding:

jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")

Have the same configuration. Added the extra jvmArgs. It runs through the code, corrects what needs corrected, leaves comments on being unable to fix Wildcards (why is that?), but ends with the same error again:

FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:ktlintFormat'. > Process 'command '/Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

@itsandreramon
Copy link
Author

Wildcards are never fixed automatically afaik

@romtsn romtsn unpinned this issue Feb 18, 2022
@tekener
Copy link

tekener commented Feb 25, 2022

I think this bug is still not fixed. In case the linter has to fix some linting issues there is still an exception module java.base does not "opens java.lang" to unnamed module.

[INFO]    [ktlint] Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.ExceptionInInitializerError
[INFO]    [ktlint]      at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
[INFO]    [ktlint]      at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
[INFO]    [ktlint]      at com.pinterest.ktlint.KtlintCommandLine.parallel(Main.kt:606)
[INFO]    [ktlint]      at com.pinterest.ktlint.KtlintCommandLine.parallel$default(Main.kt:578)
[INFO]    [ktlint]      at com.pinterest.ktlint.KtlintCommandLine.lintFiles(Main.kt:321)
[INFO]    [ktlint]      at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:282)
[INFO]    [ktlint]      at com.pinterest.ktlint.Main.main(Main.kt:76)
[INFO]    [ktlint] Caused by: java.lang.ExceptionInInitializerError
[INFO]    [ktlint]      at org.jetbrains.kotlin.com.intellij.util.exception.FrequentErrorLogger.report(FrequentErrorLogger.java:47)
[INFO]    [ktlint]      at org.jetbrains.kotlin.com.intellij.util.exception.FrequentErrorLogger.info(FrequentErrorLogger.java:43)
[INFO]    [ktlint]      at org.jetbrains.kotlin.com.intellij.psi.impl.DebugUtil.handleUnspecifiedTrace(DebugUtil.java:628)
[INFO]    [ktlint]      at org.jetbrains.kotlin.com.intellij.psi.impl.DebugUtil.currentInvalidationTrace(DebugUtil.java:620)
[INFO]    [ktlint]      at org.jetbrains.kotlin.com.intellij.psi.impl.DebugUtil.calcInvalidationTrace(DebugUtil.java:614)
[INFO]    [ktlint]      at org.jetbrains.kotlin.com.intellij.psi.impl.DebugUtil.onInvalidated(DebugUtil.java:585)
[INFO]    [ktlint]      at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.TreeElement.onInvalidated(TreeElement.java:226)
[INFO]    [ktlint]      at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.TreeElement.invalidate(TreeElement.java:328)
[INFO]    [ktlint]      at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.TreeElement.rawRemove(TreeElement.java:312)
[INFO]    [ktlint]      at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.TreeElement.rawReplaceWithList(TreeElement.java:319)
[INFO]    [ktlint]      at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafElement.rawReplaceWithText(LeafElement.java:146)
[INFO]    [ktlint]      at com.pinterest.ktlint.ruleset.standard.NoMultipleSpacesRule.visit(NoMultipleSpacesRule.kt:25)
[INFO]    [ktlint]      at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:351)
[INFO]    [ktlint]      at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:344)
[INFO]    [ktlint]      at com.pinterest.ktlint.core.VisitorProvider$sequentialVisitor$1$1$1$1.invoke(VisitorProvider.kt:102)
[INFO]    [ktlint]      at com.pinterest.ktlint.core.VisitorProvider$sequentialVisitor$1$1$1$1.invoke(VisitorProvider.kt:102)
[INFO]    [ktlint]      at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:229)
[INFO]    [ktlint]      at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:230)
[INFO]    [ktlint]      at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:230)
[INFO]    [ktlint]      at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:230)
[INFO]    [ktlint]      at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:230)
[INFO]    [ktlint]      at com.pinterest.ktlint.core.VisitorProvider$sequentialVisitor$1.invoke(VisitorProvider.kt:102)
[INFO]    [ktlint]      at com.pinterest.ktlint.core.VisitorProvider$sequentialVisitor$1.invoke(VisitorProvider.kt:94)
[INFO]    [ktlint]      at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:344)
[INFO]    [ktlint]      at com.pinterest.ktlint.internal.FileUtilsKt.formatFile(FileUtils.kt:221)
[INFO]    [ktlint]      at com.pinterest.ktlint.KtlintCommandLine.process(Main.kt:396)
[INFO]    [ktlint]      at com.pinterest.ktlint.KtlintCommandLine.access$process(Main.kt:95)
[INFO]    [ktlint]      at com.pinterest.ktlint.KtlintCommandLine$lintFiles$3.invoke$lambda-1(Main.kt:311)
[INFO]    [ktlint]      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[INFO]    [ktlint]      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[INFO]    [ktlint]      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[INFO]    [ktlint]      at java.base/java.lang.Thread.run(Thread.java:833)
[INFO]    [ktlint] 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 @43517800
[INFO]    [ktlint]      at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
[INFO]    [ktlint]      at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
[INFO]    [ktlint]      at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
[INFO]    [ktlint]      at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
[INFO]    [ktlint]      at org.jetbrains.kotlin.com.intellij.util.ReflectionUtil.findFieldInHierarchy(ReflectionUtil.java:154)
[INFO]    [ktlint]      at org.jetbrains.kotlin.com.intellij.util.ReflectionUtil.getDeclaredField(ReflectionUtil.java:279)
[INFO]    [ktlint]      at org.jetbrains.kotlin.com.intellij.openapi.util.objectTree.ThrowableInterner.<clinit>(ThrowableInterner.java:88)
[INFO]    [ktlint]      ... 32 more

@mcohen-brex
Copy link

Has anyone gotten the flags to work using bazel?

@initialjie
Copy link

0.46.1 still not working

@cmdjulian
Copy link

I'm seeing the same error with gradle 7.5 and ktlint 0.46.1
I'm seeing:
Caused by: java.lang.ClassNotFoundException: com.pinterest.ktlint.core.KtLint$Params
With version 0.45.2 this didn't occur.

@paul-dingemans
Copy link
Collaborator

I'm seeing the same error with gradle 7.5 and ktlint 0.46.1 I'm seeing: Caused by: java.lang.ClassNotFoundException: com.pinterest.ktlint.core.KtLint$Params With version 0.45.2 this didn't occur.

This is not related to Java 16. The class mentioned above has been removed in ktlint 0.46.

@anilogutveren
Copy link

Java 17-temurin
ktlint still not working with following command

mvn ktlint:format -DjvmArgs="--add-opens java.base/java.lang=ALL-UNNAMED" -DjvmArgs=" --add-exports java.base/sun.nio.ch=ALL-UNNAMED"

Error:
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

@paul-dingemans
Copy link
Collaborator

Java 17-temurin ktlint still not working with following command

mvn ktlint:format -DjvmArgs="--add-opens java.base/java.lang=ALL-UNNAMED" -DjvmArgs=" --add-exports java.base/sun.nio.ch=ALL-UNNAMED"

Error: 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

Please check whether any of workarounds mentioned in https://youtrack.jetbrains.com/issue/KT-43704

Stypox added a commit to Stypox/NewPipe that referenced this issue Apr 25, 2023
See pinterest/ktlint#1195 and ScoopInstaller/Extras#10313. Note that although this should have been fixed in the latest version of ktlint (we are using an old one), the fix doesn't seems to have worked for me.
@asmirzaei
Copy link

It worked for me by adding the following line to .mvn/jvm.config
--add-opens java.base/java.lang=ALL-UNNAMED

evermind-zz pushed a commit to bravenewpipe/BraveNewPipeLegacy that referenced this issue Aug 25, 2023
See pinterest/ktlint#1195 and ScoopInstaller/Extras#10313. Note that although this should have been fixed in the latest version of ktlint (we are using an old one), the fix doesn't seems to have worked for me.
@ikartiks
Copy link

Still fails for me on ktlint version 0.50.0
kotlin version 1.8.21
Java version 17 or 11

Everything works with ktlint version 0.40.0

@paul-dingemans
Copy link
Collaborator

Hmmm, you are updating 10 versions in one go and expect everything to work out of the box? You could try to read the changelog or search for documentation or issues. https://pinterest.github.io/ktlint/1.0.0/install/integrations/

radi-ka added a commit to radi-ka/pre-commit-jvm that referenced this issue Jan 24, 2024
see this fix in ktlint issue tracker
pinterest/ktlint#1195 (comment)
wzieba added a commit to Automattic/Automattic-Tracks-Android that referenced this issue Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.