Class NoFinalizerCheck

  • All Implemented Interfaces:
    Configurable, Contextualizable

    public class NoFinalizerCheck
    extends AbstractCheck

    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.

    To configure the check:

     <module name="NoFinalizer"/>
     

    Example:

      public class Test {
    
          protected void finalize() throws Throwable { // violation
              try {
                 System.out.println("overriding finalize()");
              } catch (Throwable t) {
                 throw t;
              } finally {
                 super.finalize();
              }
          }
      }
     

    Parent is com.puppycrawl.tools.checkstyle.TreeWalker

    Violation Message Keys:

    • avoid.finalizer.method
    Since:
    5.0