Finalize Do not override finalize (original) (raw)

The problem

Do not override Object.finalize.

Starting in JDK 18, the method is deprecated for removal, seeJEP 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 understandEffective Java Item 8, “Avoid finalizers and cleaners” very carefully, and then don’t do it.

Suppression

Suppress false positives by adding the suppression annotation to the enclosing element:

@SuppressWarnings("Finalize") // TODO(user): remove overrides of finalize