rspec/rules/S1114/java/rule.adoc
Egon Okerman d1417e82f8
Modify CWE and OWASP Top 10 links to follow standard link format (APPSEC-1134) (#3529)
* Fix all CWE references

* Fix all OWASP references

* Fix missing CWE prefixes
2024-01-15 17:15:56 +01:00

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[]