63 lines
1.4 KiB
Plaintext
63 lines
1.4 KiB
Plaintext
== Why is this an issue?
|
|
|
|
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
|
|
|
|
[source,java]
|
|
----
|
|
protected void finalize() { // Noncompliant; no call to super.finalize();
|
|
releaseSomeResources();
|
|
}
|
|
|
|
protected void finalize() {
|
|
super.finalize(); // Noncompliant; this call should come last
|
|
releaseSomeResources();
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
protected void finalize() {
|
|
releaseSomeResources();
|
|
super.finalize();
|
|
}
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
* CWE - https://cwe.mitre.org/data/definitions/568[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[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Add a call to super.finalize() at the end of this Object.finalize() implementation.
|
|
|
|
Move this super.finalize() call to the end of this Object.finalize() implementation.
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== is related to: S1115
|
|
|
|
=== on 4 Jul 2013, 12:09:44 Freddy Mallet wrote:
|
|
Is implemented by \http://jira.codehaus.org/browse/SONARJAVA-197
|
|
|
|
endif::env-github,rspecator-view[]
|