Back to Intellij Community

OverriddenMethodCallDuringObjectConstruction

java/java-impl/resources/inspectionDescriptions/OverriddenMethodCallDuringObjectConstruction.html

2025.3-rc-2866 B
Original Source

Reports any calls to overridden methods of the current class during object construction. This happens if an object construction 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 its functionality with:

  • The Abstract method called during object construction inspection
  • The Overridable method called during object construction inspection

Only one inspection should be enabled at the same time to prevent duplicate warnings.