Closed Nenrikido closed 1 year ago
The problematic statement is following:
return columns.size == otherColumns.size
&& columns.all { col ->
val otherCol = otherColumns.firstOrNull { c -> c.name() == col.name() } ?: return@all false
val result = col == otherCol
if (!result) {
println("column this[${col.name()}] != other[${otherCol.name()}]")
println("this =\n${col}")
println("other =\n${otherCol}")
}
result
}
and specifically, the line starting with &&
. The problem is caused by the chain-wrapping
rule merges the &&
with the previous line, but malforms the AST while doing so. Because of the malformed AST, the MultilineExpressionWrappingRule throws a nullpointer exception.
Change your code as follows to work around this problem for now:
override fun equals(other: Any?): Boolean {
val df = other as? DataFrame ?: return false
val otherColumns = df.columns()
return columns.size ==
otherColumns.size &&
columns.all { col ->
val otherCol = otherColumns.firstOrNull { c -> c.name() == col.name() } ?: return@all false
val result = col == otherCol
if (!result) {
println("column this[${col.name()}] != other[${otherCol.name()}]")
println("this =\n${col}")
println("other =\n${otherCol}")
}
result
}
}
The problem above can be reproduced with simplified example:
fun foo(): Boolean {
return true
&&
columns.all { col ->
false
}
}
Thanks for the quick answer, the insights, and the workaround. I will apply it in waiting for the fix.
Expected Behavior
The rule should at least pass without errors and tell me if there are linting issues or not
Observed Behavior
When running the command
mvn antrun:run@ktlint-format
with this configuration in thepom.xml
:I'm getting the error :
(I copy-pasted the interesting parts of the stack trace but if you want the full stack-trace, please tell me)
Steps to Reproduce
I'm linking to this issue 2 files where the exception arises at position 0:0, since i don't know where the bug comes from exactly in the files, I can't reduce the size of the code sample. Sorry for that KtFilesWithError.zip
My Environment