Empty Default Constructor

ID

kotlin.empty_default_constructor

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

Kotlin

Tags

constructor, empty

Description

Reports secondary constructors whose body block is present but contains no statements. An empty constructor(…​) { } adds no behaviour beyond the implicit primary constructor or delegation call.

Rationale

class Foo {
    constructor(x: Int) { }                    // FLAW — empty body
    constructor(x: Int, y: Int) : this(x) { }  // FLAW — delegation works without a body

    constructor(name: String) {
        init(name)                              // OK — body has work
    }
    constructor(x: Int, y: Int) : this(x)       // OK — no body at all
}

Empty constructors usually result from incomplete refactorings or copy-paste mistakes. They clutter the class surface and obscure which constructors carry real initialization logic.

Remediation

  • Remove the secondary constructor entirely if it adds nothing on top of the primary one.

  • Drop the empty { } body when only a delegation call is needed.

  • Add the intended initialization logic to the body.