2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-09-16 15:44:59 +02:00
include::../description.adoc[]
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-09-16 15:44:59 +02:00
2022-02-04 17:28:24 +01:00
[source,kotlin]
2021-09-16 15:44:59 +02:00
----
fun main() {
System.runFinalizersOnExit(true) // Noncompliant
}
----
2023-05-03 11:06:20 +02:00
=== Compliant solution
2021-09-16 15:44:59 +02:00
2022-02-04 17:28:24 +01:00
[source,kotlin]
2021-09-16 15:44:59 +02:00
----
fun main() {
Runtime.getRuntime().addShutdownHook(object : Thread() {
override fun run() {
doSomething()
}
})
}
----
2023-05-03 11:06:20 +02:00
== Resources
2021-09-16 15:44:59 +02:00
* https://wiki.sei.cmu.edu/confluence/x/4jZGBQ[CERT, MET12-J.] - Do not use finalizers. Although this resource talks about Java, the underlying information concerning the JVM are just as relevant for Kotlin.