Empty Else Block

ID

kotlin.empty_else_block

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Kotlin

Tags

empty, reliability

Description

Reports if expressions whose else branch is empty, making the branch dead code.

An empty else block has no observable effect at runtime. It typically results from an incomplete refactoring where the else-branch body was deleted but the else keyword and braces were left behind. The dead code adds noise, confuses readers, and may hide a missing implementation.

Rationale

// Bad — else branch is dead code
if (condition) {
    doSomething()
} else { }  // FLAW

// OK — else branch has content
if (condition) {
    doSomething()
} else {
    doOther()
}

// OK — plain if without else
if (condition) {
    doSomething()
}

Remediation

  • Remove the empty else { } if no else-case handling is needed.

  • Add the intended logic inside the else block if the branch was accidentally emptied.