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
540 stars 39 forks source link

NPE is ASTNode.squeezeSpaces method #460

Closed orchestr7 closed 3 years ago

orchestr7 commented 4 years ago

ktlint 0.37.1, diktat 0.1.2

/*
 * Copyright (c) Your Company Name Here. 2010-2020
 */

class HttpClient(var name: String) {
               var url: String = ""
    var port: String = ""
    var timeout = 0

    fun doRequest() {}
}

fun main() {
    val httpClient = HttpClient("myConnection")
        .apply {
            url = "http://pushkin.com"
            port = "8080"
            timeout = 100
        }
        .doRequest()
}

probably due to missing package directive

orchestr7 commented 4 years ago
[DEBUG] Internal Error (diktat-ruleset:too-many-spaces)
com.pinterest.ktlint.core.RuleExecutionException: java.lang.NullPointerException
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:351)
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:41)
        at com.pinterest.ktlint.core.KtLint$visitor$2$2.invoke(KtLint.kt:241)
        at com.pinterest.ktlint.core.KtLint$visitor$2$2.invoke(KtLint.kt:41)
        at com.pinterest.ktlint.core.KtLint.visit(KtLint.kt:560)
        at com.pinterest.ktlint.core.KtLint.visit(KtLint.kt:561)
        at com.pinterest.ktlint.core.KtLint.access$visit(KtLint.kt:41)
        at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:240)
        at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:41)
        at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:334)
        at com.pinterest.ktlint.internal.FileUtilsKt.formatFile(FileUtils.kt:79)
        at com.pinterest.ktlint.KtlintCommandLine.process(Main.kt:331)
        at com.pinterest.ktlint.KtlintCommandLine.access$process(Main.kt:116)
        at com.pinterest.ktlint.KtlintCommandLine$lintFiles$2$1.call(Main.kt:257)
        at com.pinterest.ktlint.KtlintCommandLine$lintFiles$2$1.call(Main.kt:116)
        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.lang.NullPointerException