Do not override finalize


The problem

Do not override Object.finalize.

Starting in JDK 18, the method is deprecated for removal, see JEP 421: Deprecate Finalization for Removal.

The Google Java Style Guide §6.4 states:

It is extremely rare to override Object.finalize.

Tip: Don’t do it. If you absolutely must, first read and understand Effective Java Item 8, “Avoid finalizers and cleaners” very carefully, and then don’t do it.


Suppress false positives by adding the suppression annotation @SuppressWarnings("Finalize") to the enclosing element.