Inspectopedia
 
2024.3

Leaking 'this' in constructor

Warning
New
Last modified: 03 December 2024

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: