CWE-572 调用线程的run()方法而非start()方法

Call to Thread run() instead of start()

结构: Simple

Abstraction: Variant

状态: Draft

被利用可能性: unkown

基本描述

The program calls a thread's run() method instead of calling start(), which causes the code to run in the thread of the caller instead of the callee.

扩展描述

In most cases a direct call to a Thread object's run() method is a bug. The programmer intended to begin a new thread of control, but accidentally called run() instead of start(), so the run() method will execute in the caller's thread of control.

相关缺陷

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

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

适用平台

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

常见的影响

范围 影响 注释
Other ['Quality Degradation', 'Varies by Context']

可能的缓解方案

Implementation

策略:

Use the start() method instead of the run() method.

示例代码

The following excerpt from a Java program mistakenly calls run() instead of start().

bad Java

Thread thr = new Thread() {
public void run() {
...
}
};

thr.run();

分类映射

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