rspec/rules/S1114/rule.adoc
Arseniy Zaostrovnykh 7ca29f686f Force linebreaks
2021-02-02 15:02:10 +01:00

35 lines
872 B
Plaintext

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