Description
The product makes an explicit call to the finalize() method from outside the finalizer.
While the Java Language Specification allows an object's finalize() method to be called from outside the finalizer, doing so is usually a bad idea. For example, calling finalize() explicitly means that finalize() will be called more than once: the first time will be the explicit call and the last time will be the call that is made after the object is garbage collected.
Potential Impact
Integrity, Other
Unexpected State, Quality Degradation
Demonstrative Examples
// time to clean up
widget.finalize();Mitigations & Prevention
Do not make explicit calls to finalize().
Detection Methods
- Automated Static Analysis High — Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then sea
Related Weaknesses
Taxonomy Mappings
- The CERT Oracle Secure Coding Standard for Java (2011): MET12-J — Do not use finalizers
- Software Fault Patterns: SFP3 — Use of an improper API
Frequently Asked Questions
What is CWE-586?
CWE-586 (Explicit Call to Finalize()) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Base-level weakness. The product makes an explicit call to the finalize() method from outside the finalizer.
How can CWE-586 be exploited?
Attackers can exploit CWE-586 (Explicit Call to Finalize()) to unexpected state, quality degradation. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-586?
Key mitigations include: Do not make explicit calls to finalize().
What is the severity of CWE-586?
CWE-586 is classified as a Base-level weakness (Medium abstraction). Its actual severity depends on the specific context and how the weakness manifests in your application.