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-intellij-plugin stops linting/formatting file with exception #2856

Closed
paul-dingemans opened this issue Nov 5, 2024 · 0 comments · Fixed by #2857
Closed

ktlint-intellij-plugin stops linting/formatting file with exception #2856

paul-dingemans opened this issue Nov 5, 2024 · 0 comments · Fixed by #2857
Milestone

Comments

@paul-dingemans
Copy link
Collaborator

The ktlint-intellij-plugin version 0.25.0-beta-2 with the ktlint 1.4.0 ruleset stops linting/formatting files with exception below:

Unhandled exception in [ComponentManager(ProjectImpl@976243401), CoroutineName(com.intellij.ide.actionsOnSave.impl.ActionsOnSaveManager), ModalityState.NON_MODAL, Dispatchers.EDT]

java.lang.NoSuchFieldError: Class org.jetbrains.kotlin.KtNodeTypes does not have member field 'org.jetbrains.kotlin.com.intellij.psi.tree.IElementType WHEN_ENTRY_GUARD'
	at com.pinterest.ktlint.ruleset.standard.rules.TrailingCommaOnDeclarationSiteRule.hasWhenGuard(TrailingCommaOnDeclarationSiteRule.kt:447)
	at com.pinterest.ktlint.ruleset.standard.rules.TrailingCommaOnDeclarationSiteRule.reportAndCorrectTrailingCommaNodeBefore(TrailingCommaOnDeclarationSiteRule.kt:261)
	at com.pinterest.ktlint.ruleset.standard.rules.TrailingCommaOnDeclarationSiteRule.visitWhenEntry(TrailingCommaOnDeclarationSiteRule.kt:184)
	at com.pinterest.ktlint.ruleset.standard.rules.TrailingCommaOnDeclarationSiteRule.beforeVisitChildNodes(TrailingCommaOnDeclarationSiteRule.kt:97)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleWithAutocorrectApproveHandlerOnNodeRecursively(RuleExecutionContext.kt:176)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleOnNodeRecursively(RuleExecutionContext.kt:102)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleWithAutocorrectApproveHandlerOnNodeRecursively(RuleExecutionContext.kt:182)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleOnNodeRecursively(RuleExecutionContext.kt:102)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleWithAutocorrectApproveHandlerOnNodeRecursively(RuleExecutionContext.kt:182)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleOnNodeRecursively(RuleExecutionContext.kt:102)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleWithAutocorrectApproveHandlerOnNodeRecursively(RuleExecutionContext.kt:182)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleOnNodeRecursively(RuleExecutionContext.kt:102)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleWithAutocorrectApproveHandlerOnNodeRecursively(RuleExecutionContext.kt:182)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleOnNodeRecursively(RuleExecutionContext.kt:102)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleWithAutocorrectApproveHandlerOnNodeRecursively(RuleExecutionContext.kt:182)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleOnNodeRecursively(RuleExecutionContext.kt:102)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleWithAutocorrectApproveHandlerOnNodeRecursively(RuleExecutionContext.kt:182)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleOnNodeRecursively(RuleExecutionContext.kt:102)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleWithAutocorrectApproveHandlerOnNodeRecursively(RuleExecutionContext.kt:182)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleOnNodeRecursively(RuleExecutionContext.kt:102)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleWithAutocorrectApproveHandlerOnNodeRecursively(RuleExecutionContext.kt:182)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleOnNodeRecursively(RuleExecutionContext.kt:102)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRule(RuleExecutionContext.kt:75)
	at com.pinterest.ktlint.rule.engine.internal.CodeFormatter.executeRule(CodeFormatter.kt:138)
	at com.pinterest.ktlint.rule.engine.internal.CodeFormatter.format(CodeFormatter.kt:109)
	at com.pinterest.ktlint.rule.engine.internal.CodeFormatter.format(CodeFormatter.kt:58)
	at com.pinterest.ktlint.rule.engine.internal.CodeFormatter.format(CodeFormatter.kt:28)
	at com.pinterest.ktlint.rule.engine.internal.CodeFormatter.format$default(CodeFormatter.kt:20)
	at com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine.format(KtLintRuleEngine.kt:145)
	at com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine.format$default(KtLintRuleEngine.kt:139)
	at com.nbadal.ktlint.KtlintFormatKt.executeKtlint(KtlintFormat.kt:118)
	at com.nbadal.ktlint.KtlintFormatKt.ktlintFormat$lambda$0(KtlintFormat.kt:51)
	at com.intellij.openapi.command.WriteCommandAction.lambda$runWriteCommandAction$4(WriteCommandAction.java:341)
	at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.lambda$doRunWriteCommandAction$1(WriteCommandAction.java:147)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteAction$lambda$4(AnyThreadWriteThreadingSupport.kt:318)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteAction(AnyThreadWriteThreadingSupport.kt:328)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteAction(AnyThreadWriteThreadingSupport.kt:318)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:890)
	at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.lambda$doRunWriteCommandAction$2(WriteCommandAction.java:145)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:226)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:188)
	at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.doRunWriteCommandAction(WriteCommandAction.java:154)
	at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.run(WriteCommandAction.java:121)
	at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:341)
	at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:329)
	at com.nbadal.ktlint.KtlintFormatKt.ktlintFormat(KtlintFormat.kt:50)
	at com.nbadal.ktlint.KtlintFormatKt.ktlintFormat$default(KtlintFormat.kt:35)
	at com.nbadal.ktlint.KtlintActionOnSave.processDocuments(KtlintActionOnSave.kt:64)
	at com.intellij.ide.actionsOnSave.impl.ActionsOnSaveManager.runActionsOnSave(ActionsOnSaveFileDocumentManagerListener.kt:220)
	at com.intellij.ide.actionsOnSave.impl.ActionsOnSaveManager.processSavedDocuments(ActionsOnSaveFileDocumentManagerListener.kt:197)
	at com.intellij.ide.actionsOnSave.impl.ActionsOnSaveManager.access$processSavedDocuments(ActionsOnSaveFileDocumentManagerListener.kt:152)
	at com.intellij.ide.actionsOnSave.impl.ActionsOnSaveManager$processSavedDocuments$1.invokeSuspend(ActionsOnSaveFileDocumentManagerListener.kt)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
	at com.intellij.openapi.application.impl.DispatchedRunnable.run(DispatchedRunnable.kt:44)
	at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:229)
	at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:22)
	at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:211)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWithImplicitRead(AnyThreadWriteThreadingSupport.kt:122)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWithImplicitRead(ApplicationImpl.java:1162)
	at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:78)
	at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:119)
	at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:41)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:781)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:728)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:750)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.kt:696)
	at com.intellij.ide.IdeEventQueue._dispatchEvent$lambda$16(IdeEventQueue.kt:590)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWithoutImplicitRead(AnyThreadWriteThreadingSupport.kt:117)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:590)
	at com.intellij.ide.IdeEventQueue.access$_dispatchEvent(IdeEventQueue.kt:73)
	at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1$1.compute(IdeEventQueue.kt:357)
	at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1$1.compute(IdeEventQueue.kt:356)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:843)
	at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.invoke(IdeEventQueue.kt:356)
	at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.invoke(IdeEventQueue.kt:351)
	at com.intellij.ide.IdeEventQueueKt$performActivity$runnableWithWIL$1.invoke$lambda$0(IdeEventQueue.kt:1035)
	at com.intellij.openapi.application.WriteIntentReadAction.lambda$run$0(WriteIntentReadAction.java:24)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteIntentReadAction(AnyThreadWriteThreadingSupport.kt:84)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteIntentReadAction(ApplicationImpl.java:910)
	at com.intellij.openapi.application.WriteIntentReadAction.compute(WriteIntentReadAction.java:55)
	at com.intellij.openapi.application.WriteIntentReadAction.run(WriteIntentReadAction.java:23)
	at com.intellij.ide.IdeEventQueueKt$performActivity$runnableWithWIL$1.invoke(IdeEventQueue.kt:1035)
	at com.intellij.ide.IdeEventQueueKt$performActivity$runnableWithWIL$1.invoke(IdeEventQueue.kt:1035)
	at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:1036)
	at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:106)
	at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:1036)
	at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$10(IdeEventQueue.kt:351)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:397)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)
	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [ComponentManager(ProjectImpl@976243401), CoroutineName(com.intellij.ide.actionsOnSave.impl.ActionsOnSaveManager), ModalityState.NON_MODAL, StandaloneCoroutine{Cancelled}@91c84d, Dispatchers.EDT]

Reason for this is that the WHEN_ENTRY_GUARD in the TrailingCommaOnDeclarationSiteRule can not be succesfully retrieved for current Kotlin version 2.0.21. The java.lang.NoSuchFieldError is not caught correctly in the KtlintRuleEngine.

@paul-dingemans paul-dingemans added this to the 1.4.1 milestone Nov 5, 2024
paul-dingemans added a commit that referenced this issue Nov 5, 2024
… kotlin version 2.0.1

As this exception was not caught in the rule, and also not in the RuleExecutionContext it terminated linting/formatting of files containing a WHEN_ENTRY with an exception. In the Ktlint CLI this exception was swallowed. In ktlint-intellij-plugin the exception was recorded and became visible to users.

Closes #2856
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant