S1481 FP with Unused variable

  • Language: Kotlin
  • Rule: S1481
  • Why do you believe it’s a false-positive/false-negative? It is used just two lines below.
  • Using:
    • SonarQube Enterprise Edition 9.9.4 (build 87374)
    • SonarLint 10.4.1.7799
      • IntelliJ Ultimate 2024.1 RC (Build #IU-241.14494.158)
      • in connected mode: yes, with SonarQube
  • Snippet:
companion object {
  fun from(formula: String): MergeRule? {
    val lhs = formula.substringBefore('=').trim().ifEmpty { return null }
    val rhs = formula.substringAfter('=', "").trim()

    val ids = lhs.split(',').map { BenefitId(it.trim()) }.takeIf { it.size > 1 } ?: return null
    val merged = rhs.takeIf(String::isNotEmpty)?.let(::BenefitId)
    return MergeRule(ids.toSet() to merged)
  }
}

Hi @efemoney,

Thank you for reporting, and sorry for the late reply!

It seems like I can’t reproduce this issue.
Can you please verify the values set for sonar.java.binaries and sonar.java.libraries to ensure they point to the correct locations?
This rule uses the Kotlin compiler diagnostics directly and may not resolve everything correctly.

All the best,

Irina

Hi Irina,
We also see several false positives for this rule in one of our GFS projects. I can share more details privately as needed.

Hi @TiKevin83,

I have the same request for you.
Can you please verify the values set for sonar.java.binaries and sonar.java.libraries to ensure they point to the correct locations?

All the best,

Irina