- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: kotlin-security/no-finalizers-on-exit
Language: Kotlin
Severity: Error
Category: Security
CWE: 833
This ensures the proper termination of Kotlin programs. It is generally considered unsafe to use the System.runFinalizersOnExit(true)
method because it can lead to unpredictable program behavior. This method forces all objects undergoing finalization to be finalized when the JVM exits, which can cause problems if an object is in the middle of a critical operation.
Instead of System.runFinalizersOnExit(true)
, you can use the Java Runtime API’s addShutdownHook
method. This method registers a new virtual-machine shutdown hook, meaning it adds a thread to run when the JVM begins its shutdown sequence. This allows you to handle any cleanup actions yourself, providing a safer and more predictable termination process.
fun foo() {
System.runFinalizersOnExit(true)
}
fun main() {
Runtime.getRuntime().addShutdownHook(object : Thread() {
override fun run() {
handleShutdown()
}
})
}
|
|
For more information, please read the Code Security documentation
Identify code vulnerabilities directly in yourVS Code editor
Identify code vulnerabilities directly inJetBrains products