Since Checkstyle 5.0
finalize
with zero parameters.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="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(); } } }
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
com.puppycrawl.tools.checkstyle.checks.coding