
org.sonar.l10n.java.rules.squid.S1186.html Maven / Gradle / Ivy
There are three reasons for a method not to have a method body:
- It is an unintentional omission, and should be fixed.
- It is not yet, or never will be, supported. In this case an
UnsupportedOperationException
should be thrown.
- The method is an intentionally-blank override. In this case a nested comment should explain the reason for the blank override.
The following code snippet:
// Non-Compliant
public void doSomething() {
}
should be refactored into:
// Compliant
@Override
public void doSomethingElse() {
// Do nothing because of X and Y.
}
or:
// Compliant
@Override
public void doSomethingElse() {
throw new UnsupportedOperationException();
}
Empty methods not having any nested comments are tolerated in Abstract classes as those empty methods are usual when implementing the visitor pattern.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy