Empty Init Block
ID |
kotlin.empty_init_block |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Kotlin |
Tags |
code_smell, empty |
Description
Reports init { } blocks whose body contains no statements.
An init block is executed during object construction to perform initialization work.
An empty init block contributes nothing and constitutes dead code. It typically results
from an incomplete implementation or from initialization logic that was removed without
deleting the surrounding block.
Rationale
class Config {
val value = 42
init { } // FLAW — empty init block has no effect
}
class ValidConfig {
val value = 42
init {
require(value > 0) { "value must be positive" } // OK
}
}
Remediation
-
Remove the empty
init { }block. -
If initialization logic is needed, add it inside the block.