Empty If Body

ID

kotlin.empty_if_body

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Kotlin

Tags

CWE:1071, empty, reliability

Description

Reports if expressions whose then-block is empty and have no else branch.

An if (condition) { } evaluates the condition but performs no action, which is almost always a typo or the result of an incomplete refactoring.

Rationale

// Bad — empty then-block, nothing happens
if (user.isActive) { }   // FLAW

// Bad — guard condition written but body forgotten
if (list.isNotEmpty()) { }  // FLAW

// Good — non-empty then-block
if (user.isActive) { activate(user) }

// Good — empty then but has else branch (at least one path does something)
if (condition) { } else { fallback() }

Remediation

Either fill in the missing body, or remove the if statement entirely if the condition was meant to be deleted. If an empty then-branch is intentional alongside an else branch, consider inverting the condition to eliminate the empty branch.