After migrating to ktlint 1.2.1 I am getting an er...
# ktlint
l
After migrating to ktlint 1.2.1 I am getting an error when attempting to suppress _property_naming_ in the following file: ExternalModel.kt
Copy code
@Suppress("ktlint:standard:property-naming")
interface ExternalModel {
    val sys_id: String?
    val table_name: String
}
Copy code
$ ./gradlew ktlintFormat
...
* What went wrong:
Execution failed for task ':runKtlintCheckOverMainSourceSet'.
> A failure occurred while executing org.jlleitschuh.gradle.ktlint.worker.KtLintWorkAction
   > 'void org.jetbrains.kotlin.psi.psiUtil.PsiUtilsKt.checkDecompiledText(org.jetbrains.kotlin.com.intellij.psi.PsiElement)'
I am using the following configuration:
Copy code
Gradle 8.6
Amazon Corretto 17.0.10-amzn
Ktlint Gradle 12.1.0
ktlint 1.2.1
Anyone come across this?
a
It appears to have broken after 1.0.1 As a workaround, replaced with:
Copy code
@Suppress("PropertyName")
interface ExternalModel {
    val sys_id: String?
    val table_name: String
}
p
I quickly tried to reproduce with Ktlint CLI, but I do not get an error. Please raise an issue and include your
.editorconfig
when you can reproduce it with the CLI version.
a
Issue is not reproducible via CLI as it is likely a fat-binary with all dependencies baked in? I re-ran Gradle with stacktraces enabled and this is what I found:
Copy code
Caused by: java.lang.NoSuchMethodError: 'void org.jetbrains.kotlin.psi.psiUtil.PsiUtilsKt.checkDecompiledText(org.jetbrains.kotlin.com.intellij.psi.PsiElement)'
  at com.pinterest.ktlint.rule.engine.internal.rules.KtlintSuppressionRule.visitKtlintSuppressionInAnnotation(KtlintSuppressionRule.kt:432)
  at com.pinterest.ktlint.rule.engine.internal.rules.KtlintSuppressionRule.beforeVisitChildNodes(KtlintSuppressionRule.kt:78)
  at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext$executeRuleOnNodeRecursively$1.invoke(RuleExecutionContext.kt:125)
  at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext$executeRuleOnNodeRecursively$1.invoke(RuleExecutionContext.kt:124)
  at com.pinterest.ktlint.rule.engine.internal.SuppressHandler.handle(SuppressHandler.kt:28)
The missing method, which ktlint engine is unable to find, is
PsiElement.checkDecompiledText
. Looking at the Kotlin sources repository, said method was not introduced until version 1.9.20: • https://github.com/JetBrains/kotlin/blob/v1.9.10/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt (missing) • https://github.com/JetBrains/kotlin/blob/v1.9.20/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt (#e9c8be3) I tested upgrading my project to Kotlin language version 1.9.20 (from 1.9.10) and Gradle task
ktlintFormat
does not fail anymore.
p
CLI is indeed a fat binary including the embedded kotlin compiler.
The missing method, which ktlint engine is unable to find, is
PsiElement.checkDecompiledText
. Looking at the Kotlin sources repository, said method was not introduced until version 1.9.20:
That is a very good find. The call to
checkDecompiledText
is not made directly by
KtlintRuleEngine
. I would need the full stack trace to find the root cause of it.
l
I can do one better. I've created a small demo project along with some usage instructions at the following location: https://github.com/alex-arana/ktlint-demo
161 Views