2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2021-09-16 15:44:59 +02:00
|
|
|
include::../description.adoc[]
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Noncompliant code example
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2023-06-09 16:48:57 +02:00
|
|
|
[source,java,diff-id=1,diff-type=noncompliant]
|
2021-04-28 16:49:39 +02:00
|
|
|
----
|
|
|
|
public static void main(String [] args) {
|
|
|
|
System.runFinalizersOnExit(true); // Noncompliant
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void finalize(){
|
2023-06-05 16:34:49 +02:00
|
|
|
doShutdownOperations();
|
2021-04-28 16:49:39 +02:00
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Compliant solution
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2023-06-09 16:48:57 +02:00
|
|
|
[source,java,diff-id=1,diff-type=compliant]
|
2021-04-28 16:49:39 +02:00
|
|
|
----
|
|
|
|
public static void main(String [] args) {
|
2023-06-05 16:34:49 +02:00
|
|
|
Thread myThread = new Thread( () -> { doShutdownOperations(); });
|
|
|
|
Runtime.getRuntime().addShutdownHook(myThread);
|
|
|
|
}
|
2021-04-28 16:49:39 +02:00
|
|
|
----
|
|
|
|
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
== Resources
|
2021-04-28 16:49:39 +02:00
|
|
|
|
|
|
|
* https://wiki.sei.cmu.edu/confluence/x/4jZGBQ[CERT, MET12-J.] - Do not use finalizers
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== Message
|
|
|
|
|
|
|
|
Remove this call to "XXX.runFinalizersOnExit()".
|
|
|
|
|
2021-09-20 15:38:42 +02:00
|
|
|
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== on 25 Nov 2014, 16:45:38 Freddy Mallet wrote:
|
|
|
|
@Ann, according to my compliant solution I would increase the remediation cost to 20 minutes.
|
|
|
|
|
|
|
|
=== on 16 Jan 2015, 09:40:23 Sébastien Gioria wrote:
|
|
|
|
Could be tag security and cwe :
|
|
|
|
|
|
|
|
CERT Secure Coding reference : \https://www.securecoding.cert.org/confluence/display/java/MET12-J.+Do+not+use+finalizers
|
|
|
|
|
|
|
|
CWE : \http://cwe.mitre.org/data/definitions/586.html
|
|
|
|
|
|
|
|
=== on 19 Jan 2015, 08:39:06 Ann Campbell wrote:
|
|
|
|
\[~sebastien.gioria], I've added the CERT reference, but not the one for CWE, which seems to have a pretty narrow scope.
|
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|