rspec/rules/S1114/java/rule.adoc

54 lines
1.2 KiB
Plaintext
Raw Normal View History

== 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
2022-02-04 17:28:24 +01:00
[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
2022-02-04 17:28:24 +01:00
[source,java]
----
protected void finalize() {
releaseSomeResources();
super.finalize();
}
----
== Resources
* https://cwe.mitre.org/data/definitions/568[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[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]