Inspectopedia 2025.2 Help

Leaking 'this' in constructor

Reports unsafe operations with this during object construction including:

  • Accessing a non-final property during class initialization: from a constructor or property initialization

  • Calling a non-final function during class initialization

  • Using this as a function argument in a constructor of a non-final class

If other classes inherit from the given class, they may not be fully initialized at the moment when an unsafe operation is carried out.

Example:

abstract class Base { val code = calculate() abstract fun calculate(): Int } class Derived(private val x: Int) : Base() { override fun calculate() = x } fun testIt() { println(Derived(42).code) // Expected: 42, actual: 0 }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

LeakingThis
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Kotlin | Probable bugs

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection LeakingThis

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

IntelliJ IDEA 2025.2, Qodana for JVM 2025.2,

Last modified: 18 September 2025