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-core incompatible with latest JDK LTS (JDK 17) #1943

Closed
leinardi opened this issue Apr 14, 2023 · 2 comments
Closed

ktlint-core incompatible with latest JDK LTS (JDK 17) #1943

leinardi opened this issue Apr 14, 2023 · 2 comments

Comments

@leinardi
Copy link
Contributor

Expected Behavior

If you follow the instruction on how to directly format some code using the artifact ktlint-code, you are forced to use JDK 11 because on JDK 17, the latest LTS, you get a java.lang.ExceptionInInitializerError.

Observed Behavior

When executing ktLintRuleEngine.format() the following exception is thrown when using JDK 17 (works fine with JDK 11):

Exception in thread "main" 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:127)
	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.beforeVisitChildNodes(ImportOrderingRule.kt:116)
	at com.pinterest.ktlint.core.internal.RuleExecutionContext$executeRuleOnNodeRecursively$1.invoke(RuleExecutionContext.kt:66)
	at com.pinterest.ktlint.core.internal.RuleExecutionContext$executeRuleOnNodeRecursively$1.invoke(RuleExecutionContext.kt:65)
	at com.pinterest.ktlint.core.internal.SuppressHandler.handle(SuppressHandler.kt:25)
	at com.pinterest.ktlint.core.internal.RuleExecutionContext.executeRuleOnNodeRecursively(RuleExecutionContext.kt:65)
	at com.pinterest.ktlint.core.internal.RuleExecutionContext.access$executeRuleOnNodeRecursively(RuleExecutionContext.kt:23)
	at com.pinterest.ktlint.core.internal.RuleExecutionContext$executeRuleOnNodeRecursively$2$1.invoke(RuleExecutionContext.kt:73)
	at com.pinterest.ktlint.core.internal.RuleExecutionContext$executeRuleOnNodeRecursively$2$1.invoke(RuleExecutionContext.kt:72)
	at com.pinterest.ktlint.core.internal.SuppressHandler.handle(SuppressHandler.kt:25)
	at com.pinterest.ktlint.core.internal.RuleExecutionContext.executeRuleOnNodeRecursively(RuleExecutionContext.kt:72)
	at com.pinterest.ktlint.core.internal.RuleExecutionContext.executeRule(RuleExecutionContext.kt:47)
	at com.pinterest.ktlint.core.KtLintRuleEngine$format$4.invoke(KtLint.kt:517)
	at com.pinterest.ktlint.core.KtLintRuleEngine$format$4.invoke(KtLint.kt:516)
	at com.pinterest.ktlint.core.internal.VisitorProvider$visitor$6.invoke(VisitorProvider.kt:90)
	at com.pinterest.ktlint.core.internal.VisitorProvider$visitor$6.invoke(VisitorProvider.kt:88)
	at com.pinterest.ktlint.core.KtLintRuleEngine.format(KtLint.kt:516)
	at com.pinterest.ktlint.core.KtLintRuleEngine.format$default(KtLint.kt:497)
	at org.gtkkn.gir.generator.KtLintFormatter.formatAndWriteKotlinFile(KtLintFormatter.kt:61)
	at org.gtkkn.gir.generator.BindingsGenerator.writeType(BindingsGenerator.kt:155)
	at org.gtkkn.gir.generator.BindingsGenerator.writeType$default(BindingsGenerator.kt:131)
	at org.gtkkn.gir.generator.BindingsGenerator.generate(BindingsGenerator.kt:56)
	at org.gtkkn.gir.MainKt.main(Main.kt:56)
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 @11614aef
	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)
	... 39 more

Steps to Reproduce

  1. Make sure to have JDK 17 and necessary dependencies installed: apt-get --quiet install --yes openjdk-17-jdk gcc-multilib libgirepository1.0-dev libadwaita-1-dev
  2. Clone this repository: git clone https://gitlab.com/gtk-kn/gtk-kn.git
  3. Checkout the branch feature/67-jdk17: git checkout feature/67-jdk17
  4. Execute the Gradle task :gir:run: ./gradlew :gir:run

Your Environment

  • Version of ktlint used: 0.48.2
  • Relevant parts of the .editorconfig settings: https://gitlab.com/gtk-kn/gtk-kn/-/blob/feature/67-jdk17/.editorconfig
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): Maven Central artifact com.pinterest.ktlint:ktlint-core:0.48.2
  • Version of Gradle used (if applicable): 7.6
  • Operating System and version: Ubuntu 22.04
@leinardi
Copy link
Contributor Author

I saw that a similar ticket was open and closed: #1391
The ticket provides a workaround but, after more than one year, there is still no proper fix. It seems to be an issues with some dependencies of KtLint. I would still keep the ticket open until a proper fix is available.

@paul-dingemans
Copy link
Collaborator

Duplicate. See #1618

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants