CWE-586 对Finalize()的显式调用

Explicit Call to Finalize()

结构: Simple

Abstraction: Variant

状态: Draft

被利用可能性: unkown

基本描述

The software 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.

相关缺陷

  • cwe_Nature: ChildOf cwe_CWE_ID: 1076 cwe_View_ID: 1000 cwe_Ordinal: Primary

  • cwe_Nature: ChildOf cwe_CWE_ID: 1076 cwe_View_ID: 699 cwe_Ordinal: Primary

适用平台

Language: {'cwe_Name': 'Java', 'cwe_Prevalence': 'Undetermined'}

常见的影响

范围 影响 注释
['Integrity', 'Other'] ['Unexpected State', 'Quality Degradation']

可能的缓解方案

['Implementation', 'Testing']

策略:

Do not make explicit calls to finalize(). Use static analysis tools to spot such instances.

示例代码

The following code fragment calls finalize() explicitly:

bad Java


// time to clean up
widget.finalize();

分类映射

映射的分类名 ImNode ID Fit Mapped Node Name
The CERT Oracle Secure Coding Standard for Java (2011) MET12-J Do not use finalizers
Software Fault Patterns SFP3 Use of an improper API