Reports any calls to overridden methods of the current class during object construction.
A call is during object construction if it is inside:
- A Constructor
- A Non-static instance initializer
- A Non-static field initializer
clone()
readObject()
readObjectNoData()
Such calls may result in subtle bugs, as the object is not guaranteed to be initialized before the method call occurs.
Example:
abstract class Parent {
void someMethod() { }
}
class Child extends Parent {
Child() {
someMethod();
}
@Override
void someMethod() { }
}
This inspection shares functionality with:
- Abstract method called during object construction inspection
- Overridable method called during object construction inspection
Only one inspection should be enabled at the same time to prevent duplicate warnings.