else branch has an empty body

ID

scala.correctness.empty_else_block

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Dead Code

Language

Scala

Description

Reports an else branch whose body is an empty block, so the branch exists but does nothing.

Rationale

An empty else is indistinguishable from an unfinished one: a reader cannot tell whether the case was deliberately ignored or whether the handling was never written or was deleted during a refactor. It also adds a branch that coverage tooling and tests must account for while contributing no behaviour.

The following code illustrates the pattern detected by this rule:

class EmptyElseBlock {
  def guard(n: Int): Unit = {
    // FLAGGED: else branch has an empty body
    if (n > 0) {
      println("positive")
    } else {}
  }
}

Remediation

Delete the else branch if there is genuinely nothing to do, so the code states that plainly. If the case does need handling, write it - and if the omission is intentional and non-obvious, record why in a comment rather than in an empty block.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved