Back to Intellij Community

Finalize

java/java-impl/resources/inspectionDescriptions/Finalize.html

2025.3-rc-21.1 KB
Original Source

Reports overriding the Object.finalize() method.

According to the Object.finalize() documentation:

The finalization mechanism is inherently problematic. Finalization can lead to performance issues, deadlocks, and hangs. Errors in finalizers can lead to resource leaks; there is no way to cancel finalization if it is no longer necessary; and no ordering is specified among calls to finalize methods of different objects. Furthermore, there are no guarantees regarding the timing of finalization. The finalize method might be called on a finalizable object only after an indefinite delay, if at all.

Configure the inspection:

  • Use the Ignore for trivial 'finalize()' implementations option to ignore finalize() implementations with an empty method body or a body containing only if statements that have a condition which evaluates to false and is a compile-time constant. For performance reasons it can be beneficial to override a non-trivial finalize() with an empty implementation in a subclass. An empty final finalize() implementation can also be used to prevent subclasses from overriding.