EmptyMethod

SUGGESTION

Simplification

View source code on GitHub

Summary

Empty method can likely be deleted

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("EmptyMethod") to the enclosing element.

Disable this pattern completely by adding -Xep:EmptyMethod:OFF as compiler argument. Learn more.

Samples

Replacement

Shows the difference in example code before and after the bug pattern is applied.

 final class A {
-  void instanceMethod() {}
-
-  static void staticMethod() {}
-
   static void staticMethodWithComment() {
     /* Foo. */
   }
 }
 

Identification

Shows code lines which will (not) be flagged by this bug pattern.
A //BUG: Diagnostic contains: comment is placed above any violating line.

class A {
  Object m1() {
    return null;
  }

  void m2() {
    System.out.println(42);
  }

  void m3() {}

  // BUG: Diagnostic contains:
  static void m4() {}

  interface F {
    void fun();
  }

  final class MyTestClass {
    void helperMethod() {}
  }
}
import org.aspectj.lang.annotation.Pointcut;

final class B implements A.F {
  @Override
  public void fun() {}

  // BUG: Diagnostic contains:
  void m3() {}

  /** Javadoc. */
  // BUG: Diagnostic contains:
  void m4() {}

  void m5() {
    // Single-line comment.
  }

  void m6() {
    /* Multi-line comment. */
  }

  @Pointcut
  void m7() {}
}

Copyright © 2017-2024 Picnic Technologies BV