-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathRunMethodCalledOnJavaLangThreadDirectly.ql
More file actions
51 lines (46 loc) · 1.53 KB
/
RunMethodCalledOnJavaLangThreadDirectly.ql
File metadata and controls
51 lines (46 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* @id java/run-method-called-on-java-lang-thread-directly
* @name J-D-001: Method call to `java.lang.Thread` or its subclasses may indicate a logical bug
* @description Calling `run()` on `java.lang.Thread` or its subclasses may indicate
* misunderstanding on the programmer's part.
* @kind problem
* @precision very-high
* @problem.severity warning
* @tags correctness
* performance
* concurrency
*/
import java
import semmle.code.java.dataflow.DataFlow
/**
* The import statement that brings java.lang.Thread into scope.
*/
class JavaLangThreadImport extends ImportType {
JavaLangThreadImport() { this.getImportedType().hasQualifiedName("java.lang", "Thread") }
}
/**
* A class that inherits from `java.lang.Thread` either directly or indirectly.
*/
class JavaLangThreadSubclass extends Class {
JavaLangThreadSubclass() {
exists(JavaLangThreadImport javaLangThread |
this.getASupertype+() = javaLangThread.getImportedType()
)
}
}
class ProblematicRunMethodCall extends MethodCall {
ProblematicRunMethodCall() {
this.getMethod().getName() = "run" and
(
exists(JavaLangThreadImport javaLangThread |
this.getQualifier().getType() = javaLangThread.getImportedType()
)
or
exists(JavaLangThreadSubclass javaLangThreadSubclass |
this.getQualifier().getType() = javaLangThreadSubclass
)
)
}
}
from ProblematicRunMethodCall problematicRunMethodCall
select problematicRunMethodCall, "The run method is called directly on a thread instance."