NoFinalizer

Since Checkstyle 5.0

Description

Checks that there is no method finalize with zero parameters.

See Object.finalize()

Rationale: Finalizers are unpredictable, often dangerous, and generally unnecessary. Their use can cause erratic behavior, poor performance, and portability problems. For more information for the finalize method and its issues, see Effective Java: Programming Language Guide Third Edition by Joshua Bloch, §8.

Examples

To configure the check:

<module name="Checker">
  <module name="TreeWalker">
    <module name="NoFinalizer"/>
  </module>
</module>
        

Example:

public class Example1 {
  // violation below, 'Avoid using finalizer method'
  protected void finalize() throws Throwable {
    try {
      System.out.println("overriding finalize()");
    } catch (Throwable t) {
      throw t;
    } finally {
      super.finalize();
    }
  }
}
        

Example of Usage

Violation Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.coding

Parent Module

TreeWalker