Empty Function Body
ID |
kotlin.empty_function_body |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Kotlin |
Tags |
best-practice, code-style |
Description
Reports function declarations whose block body contains no statements (fun foo() {}).
An empty body is almost always either a stub that was never filled in or a placeholder
that should have been declared abstract.
Rationale
A function with an empty body compiles and runs, but performs no work. This is usually
a sign of an incomplete implementation. When an empty implementation is genuinely
intentional — for example a no-op lifecycle override — the function should be declared
abstract (if the class is abstract) or removed from the override chain entirely.
Leaving a silent empty body makes code harder to reason about.
// Bad
fun doWork() {}
override fun onStop() {}
// Good
abstract fun doWork()
// No override at all if the super call is not needed
Remediation
Either implement the function body, declare the function abstract, or remove the
override entirely if the parent implementation already does nothing.