nbadal / ktlint-intellij-plugin

Ktlint plugin for IntelliJ IDEA + Android Studio
MIT License
166 stars 24 forks source link

Specifying ktlint_code_style in .editorconfig causes plugin to crash #272

Closed gschulze closed 1 year ago

gschulze commented 1 year ago

When adding ktlint_code_style = official or ktlint_code_style = android to .editorconfig, the plugin crashes with the following exception:

com.intellij.diagnostic.PluginException: annotator: com.nbadal.ktlint.KtlintAnnotator@2c880359 (class com.nbadal.ktlint.KtlintAnnotator) [Plugin: com.nbadal.ktlint]
    at com.intellij.diagnostic.PluginProblemReporterImpl.createPluginExceptionByClass(PluginProblemReporterImpl.java:23)
    at com.intellij.diagnostic.PluginException.createByClass(PluginException.java:83)
    at com.intellij.codeInsight.daemon.impl.ExternalToolPass.processError(ExternalToolPass.java:263)
    at com.intellij.codeInsight.daemon.impl.ExternalToolPass.collectInformationWithProgress(ExternalToolPass.java:138)
    at com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.doCollectInformation(ProgressableTextEditorHighlightingPass.java:97)
    at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:57)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$1(PassExecutorService.java:379)
    at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1111)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:371)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:604)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:679)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:635)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:603)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:370)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:346)
    at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:173)
    at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:182)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:344)
    at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:181)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class com.pinterest.ktlint.core.api.DefaultEditorConfigProperties$CodeStyleValue (java.lang.String is in module java.base of loader 'bootstrap'; com.pinterest.ktlint.core.api.DefaultEditorConfigProperties$CodeStyleValue is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @611dcdaf)
    at com.pinterest.ktlint.core.api.UsesEditorConfigProperties$DefaultImpls.getEditorConfigValue(UsesEditorConfigProperties.kt:50)
    at com.pinterest.ktlint.core.internal.VisitorProvider.getEditorConfigValue(VisitorProvider.kt:17)
    at com.pinterest.ktlint.core.internal.VisitorProvider.isNotDisabled(VisitorProvider.kt:132)
    at com.pinterest.ktlint.core.internal.VisitorProvider.visitor$ktlint_core(VisitorProvider.kt:43)
    at com.pinterest.ktlint.core.internal.VisitorProvider.visitor$ktlint_core$default(VisitorProvider.kt:37)
    at com.pinterest.ktlint.core.KtLint.lint(KtLint.kt:140)
    at com.nbadal.ktlint.KtLintWrapper.lint(KtLintWrapper.kt:10)
    at com.nbadal.ktlint.KtlintProcessingKt.doLint(KtlintProcessing.kt:99)
    at com.nbadal.ktlint.KtlintAnnotator.collectInformation(KtlintAnnotator.kt:21)
    at com.nbadal.ktlint.KtlintAnnotator.collectInformation(KtlintAnnotator.kt:14)
    at com.intellij.lang.annotation.ExternalAnnotator.collectInformation(ExternalAnnotator.java:60)
    at com.intellij.codeInsight.daemon.impl.ExternalToolPass.collectInformationWithProgress(ExternalToolPass.java:135)
    ... 21 more

Running ktlint from the command line with the same .editorconfig works just fine.

nbadal commented 1 year ago

Will take a look, thanks for the report!

paul-dingemans commented 1 year ago

Most likely this problem occurred due to a difference between hte version of Ktlint CLI and the Ktlint version embedded in the plugin. Problem can not be reproduced when using an unknown value for property "ktlint_code_style".