Empty While Block
ID |
kotlin.empty_while_block |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Kotlin |
Tags |
empty, loop |
Description
Reports while loops whose body is empty.
A while (condition) { } re-evaluates its condition repeatedly but performs no work in the body. Unless the condition expression itself has a side effect, the loop will either run forever or terminate immediately — neither of which is intentional.
Rationale
// Bad — empty body, condition checked but nothing consumed
while (queue.isNotEmpty()) { } // FLAW
// Good — non-empty body
while (queue.isNotEmpty()) {
process(queue.poll())
}
Remediation
Either fill in the missing body, or remove the while loop entirely if the condition check was no longer needed after a refactoring.