SuperFinalize

Since Checkstyle 3.2

Description

Checks that an overriding finalize() method invokes super.finalize(). Does not check native methods, as they have no possible java defined implementation.

References: How to Handle Java Finalization's Memory-Retention Issues; 10 points on finalize method in Java.

Examples

To configure the check:

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

Example:

public class A {
      protected void finalize() throws Throwable {
            System.out.println("In finalize block");
            super.finalize(); // OK, calls super.finalize()
      }
}
public class B {
      protected void finalize() throws Throwable { // violation
            System.out.println("In finalize block");
      }
}
        

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