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:

class Example1 {
  protected void finalize() throws Throwable {
    super.finalize(); // OK, calls super.finalize()
  }
}
class InvalidExample {
  // violation below, 'Method 'finalize' should call 'super.finalize''
  protected void finalize() throws Throwable {
  }
}
        

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