Class FinalizeImplementationCheck

  • All Implemented Interfaces:
    com.puppycrawl.tools.checkstyle.api.Configurable, com.puppycrawl.tools.checkstyle.api.Contextualizable

    public class FinalizeImplementationCheck
    extends com.puppycrawl.tools.checkstyle.api.AbstractCheck
    Validates finalize method implementation.

    This Check detects 3 most common cases of incorrect finalize() method implementation:

    1. Negates effect of superclass finalize:

     protected void finalize() { }
     protected void finalize() { doSomething(); }
     

    2. Useless (or worse) finalize:

     protected void finalize() { super.finalize(); }
     

    3. Public finalize:

     public void finalize(){
         try {doSomething();}
         finally {super.finalize()}
     }
    Since:
    1.11.0
    Author:
    Max Vetrenko
    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean

        com.puppycrawl.tools.checkstyle.api.AutomaticBean.OutputStreamOptions
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int[] getAcceptableTokens()  
      int[] getDefaultTokens()  
      int[] getRequiredTokens()  
      void visitToken​(com.puppycrawl.tools.checkstyle.api.DetailAST methodDefToken)  
      • Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck

        beginTree, clearViolations, destroy, finishTree, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokens
      • Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter

        finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
      • Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean

        configure, contextualize, getConfiguration, setupChild
    • Field Detail

      • MSG_KEY_MISSED_TRY_FINALLY

        public static final String MSG_KEY_MISSED_TRY_FINALLY
        The key is pointing to the warning message text in "messages.properties" file.
        See Also:
        Constant Field Values
      • MSG_KEY_PUBLIC_FINALIZE

        public static final String MSG_KEY_PUBLIC_FINALIZE
        The key is pointing to the warning message text in "messages.properties" file.
        See Also:
        Constant Field Values
      • MSG_KEY_USELESS_FINALIZE

        public static final String MSG_KEY_USELESS_FINALIZE
        The key is pointing to the warning message text in "messages.properties" file.
        See Also:
        Constant Field Values
      • MSG_KEY_MISSED_SUPER_FINALIZE_CALL

        public static final String MSG_KEY_MISSED_SUPER_FINALIZE_CALL
        The key is pointing to the warning message text in "messages.properties" file.
        See Also:
        Constant Field Values
    • Constructor Detail

      • FinalizeImplementationCheck

        public FinalizeImplementationCheck()
    • Method Detail

      • getDefaultTokens

        public int[] getDefaultTokens()
        Specified by:
        getDefaultTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheck
      • getAcceptableTokens

        public int[] getAcceptableTokens()
        Specified by:
        getAcceptableTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheck
      • getRequiredTokens

        public int[] getRequiredTokens()
        Specified by:
        getRequiredTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheck
      • visitToken

        public void visitToken​(com.puppycrawl.tools.checkstyle.api.DetailAST methodDefToken)
        Overrides:
        visitToken in class com.puppycrawl.tools.checkstyle.api.AbstractCheck