Empty Method Body

ID

java.empty_function_body

Severity

high

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Code Smell

Language

Java

Tags

code_smell, maintainability

Description

Reports a method or constructor whose body is present but holds no statement and no comment. An abstract or interface method, which has no body at all, is never a candidate.

Several shapes are left alone: a body holding only a comment explaining the blank implementation; a method whose enclosing class is abstract; a method that implements or overrides a method declared by a supertype, with or without @Override; a method annotated @Pointcut; a non-public no-argument constructor; and a public no-argument constructor when the class declares other constructors alongside it.

@Override is optional in Java, so the exemption follows the contract rather than the annotation: an empty refreshUiReal() whose superclass declares it abstract is as deliberate as an annotated one, and its author can change neither the name nor the signature. The supertype chain is read from the project-wide software model, which indexes the scanned sources only — an empty override of a JDK or third-party class is invisible to it and is still reported.

Rationale

An empty body brings no functionality and misleads a reader into thinking it fulfils some requirement. It is usually one of three things: an unintentional omission that should be filled in, a not-yet-supported operation that should throw instead of silently doing nothing, or a deliberate blank override that was never documented as such.

@Override
public void onStop() {   // FLAW -- does this intentionally do nothing, or was it never finished?
}

The @Override above does not exempt it. The exemption follows the supertype, not the annotation, and the supertype chain is read from the project-wide software model, which indexes the scanned sources only. onStop() here overrides a framework class that is not part of the scanned project, so no declaring supertype is found and the empty body is reported. An empty override of a class declared inside the scanned sources is exempt, with or without @Override.

Remediation

Implement the method, throw an exception if the operation is unsupported, or add a comment recording that the empty body is deliberate.

@Override
public void onStop() {
  // Nothing to release: this screen holds no resources.
}

References

© 2026 Xygeni. All rights reserved