Java

Java

By DeepSource

Finalizers must not be explicitly invokedJAVA-E0094

Anti-pattern

This method explicitly invokes an object's finalize method. Because finalizer methods are supposed to be executed once, and only by the JVM's internal code, this is a bad idea.

Examples

Bad Practice

this.finalize();

If a connected set of objects is currently being finalized, there is a chance that the finalize method of all such objects could be called at the same time by the JVM over multiple threads. If the finalize method were to be invoked on such a connected object at the same time as its finalize method was called by the JVM, it could cause a virtually impossible to diagnose race condition.

Recommended

Remove the call to finalize.

Note: Finalizers are deprecated since Java 9.

References