You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ktlint crashes with an internal error when running on a specific file due to a NoSuchElementException in TrailingCommaRule when using --experimental.
Steps to Reproduce
In an empty folder, create a file Test.kt with the following contents:
classTest {
var foo =Bar()
set(value) {
}
}
Run ktlint --experimental --debug Test.kt.
ktlint produces an output similar to the following:
[DEBUG] Discovered ruleset with " standard" id.
[DEBUG] Discovered ruleset with "experimental" id.
[DEBUG] Discovered reporter with "baseline" id.
[DEBUG] Discovered reporter with "checkstyle" id.
[DEBUG] Discovered reporter with "json" id.
[DEBUG] Discovered reporter with "html" id.
[DEBUG] Discovered reporter with "plain" id.
[DEBUG] Discovered reporter with "sarif" id.
[DEBUG] Initializing "plain" reporter with {verbose=false, color=false, color_name=DARK_GRAY}
[DEBUG] Checking D:\tmp\Test.kt
Resolving .editorconfig files for D:\tmp\Test.kt file path
Loaded .editorconfig: []
[DEBUG] Internal Error (experimental:trailing-comma)
com.pinterest.ktlint.core.RuleExecutionException: java.util.NoSuchElementException: Sequence contains no
element matching the predicate.
at com.pinterest.ktlint.core.KtLint$lint$1.invoke(KtLint.kt:166)
at com.pinterest.ktlint.core.KtLint$lint$1.invoke(KtLint.kt:147)
at com.pinterest.ktlint.core.KtLint$visitor$2$3.invoke(KtLint.kt:317)
at com.pinterest.ktlint.core.KtLint$visitor$2$3.invoke(KtLint.kt:315)
at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:229)
at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:230)
at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:230)
at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:230)
at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:230)
at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:230)
at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:315)
at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:293)
at com.pinterest.ktlint.core.KtLint.lint(KtLint.kt:147)
at com.pinterest.ktlint.internal.FileUtilsKt.lintFile(FileUtils.kt:172)
at com.pinterest.ktlint.KtlintCommandLine.process(Main.kt:395)
at com.pinterest.ktlint.KtlintCommandLine.access$process(Main.kt:89)
at com.pinterest.ktlint.KtlintCommandLine$lintFiles$3.invoke$lambda-0(Main.kt:289)
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:834)
Caused by: java.util.NoSuchElementException: Sequence contains no element matching the predicate.
at com.pinterest.ktlint.ruleset.experimental.trailingcomma.TrailingCommaRule.visitValueList(TrailingCommaRule.kt:357)
at com.pinterest.ktlint.ruleset.experimental.trailingcomma.TrailingCommaRule.visit(TrailingCommaRule.kt:61)
at com.pinterest.ktlint.core.KtLint$lint$1.invoke(KtLint.kt:154)
... 20 more
D:\tmp\Test.kt:3:9: Internal Error (experimental:trailing-comma). Please create a ticket at https://github.com/pinterest/ktlint/issues (if possible, please re-run with the --debug flag to get the stacktrace and provide the source code that triggered an error) (cannot be auto-corrected)
[DEBUG] 1625ms / 1 file(s) / 1 error(s)
Additional Information
I was just migrating my project ltex-ls to use the new trailing-comma rules when I discovered this. However, the bug occurs even if the trailing-comma rules have not been enabled (no .editorconfig file or trailing-comma rules explicitly set to false). It suffices to use --experimental to trigger the bug.
Your Environment
Version of ktlint used: 0.43.0
Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): Command-line ktlint
Expected Behavior
ktlint doesn't crash with an internal error.
Observed Behavior
ktlint crashes with an internal error when running on a specific file due to a
NoSuchElementException
inTrailingCommaRule
when using--experimental
.Steps to Reproduce
Test.kt
with the following contents:ktlint --experimental --debug Test.kt
.Additional Information
I was just migrating my project ltex-ls to use the new
trailing-comma
rules when I discovered this. However, the bug occurs even if thetrailing-comma
rules have not been enabled (no.editorconfig
file ortrailing-comma
rules explicitly set tofalse
). It suffices to use--experimental
to trigger the bug.Your Environment
The text was updated successfully, but these errors were encountered: