saveourtool / diktat

Strict coding standard for Kotlin and a custom set of rules for detecting code smells, code style issues and bugs
https://diktat.saveourtool.com
MIT License
521 stars 39 forks source link

`ClassCastException` due to `ktlint_code_style` in `.editorconfig` #1707

Closed adamsmd closed 10 months ago

adamsmd commented 1 year ago

Describe the bug

It seems that adding ktlint_code_style to .editorconfig causes a ClassCastException.

Steps to Reproduce

Add this to .editorconfig:

[*.{kt,kts}]
ktlint_code_style = official

(I am not sure if it matters, but I have tested this with both ktlint 0.48.2 and 0.49.1.)

Note that this problem also exists if setting to ktlint_official (what ktlint 0.49.1 uses) instead of official (what ktlint 0.48.2 uses).

Expected behavior

That ./gradlew clean diktatCheck runs without throwing an exception.

Observed behavior

$ ./gradlew clean diktatCheck

> Task :simpleCykParser:diktatCheck
Exception in thread "main" java.util.concurrent.ExecutionException: 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 'app')
        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.internal.KtlintCommandLine.parallel(KtlintCommandLine.kt:578)
        at com.pinterest.ktlint.internal.KtlintCommandLine.parallel$default(KtlintCommandLine.kt:536)
        at com.pinterest.ktlint.internal.KtlintCommandLine.lintFiles(KtlintCommandLine.kt:283)
        at com.pinterest.ktlint.internal.KtlintCommandLine.run(KtlintCommandLine.kt:235)
        at com.pinterest.ktlint.Main.main(Main.kt:31)
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 'app')
        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.pinterest.ktlint.internal.FileUtilsKt.lintFile(FileUtils.kt:174)
        at com.pinterest.ktlint.internal.KtlintCommandLine.process(KtlintCommandLine.kt:384)
        at com.pinterest.ktlint.internal.KtlintCommandLine.access$process(KtlintCommandLine.kt:48)
        at com.pinterest.ktlint.internal.KtlintCommandLine$lintFiles$3.invoke$lambda-1(KtlintCommandLine.kt:274)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)

Environment information

nulls commented 1 year ago

hi @adamsmd, thanks for raising the issue. We will look on it

nulls commented 10 months ago

The issue is fixed in new version of diktat 2.0.0.

A new version will be released soon.

Thanks