rspec/rules/S1114/java/rule.adoc

42 lines
1007 B
Plaintext
Raw Normal View History

Overriding the ``++Object.finalize()++`` method must be done with caution to dispose some system resources.
Calling the ``++super.finalize()++`` at the end of this method implementation is highly recommended in case parent implementations must also dispose some system resources.
== Noncompliant Code Example
----
protected void finalize() { // Noncompliant; no call to super.finalize();
releaseSomeResources();
}
protected void finalize() {
super.finalize(); // Noncompliant; this call should come last
releaseSomeResources();
}
----
== Compliant Solution
----
protected void finalize() {
releaseSomeResources();
super.finalize();
}
----
== See
* http://cwe.mitre.org/data/definitions/568.html[MITRE, CWE-568] - finalize() Method Without super.finalize()
* https://wiki.sei.cmu.edu/confluence/x/4jZGBQ[CERT, MET12-J.] - Do not use finalizers
ifdef::rspecator-view[]
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::rspecator-view[]