43 lines
1.0 KiB
Plaintext
43 lines
1.0 KiB
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
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|