-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathYieldCalls.ql
More file actions
30 lines (26 loc) · 838 Bytes
/
YieldCalls.ql
File metadata and controls
30 lines (26 loc) · 838 Bytes
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
/**
* @name Call to Thread.yield()
* @description Calling 'Thread.yield' may have no effect, and is not a reliable way to prevent a
* thread from taking up too much execution time.
* @kind problem
* @problem.severity warning
* @precision low
* @id java/thread-yield-call
* @tags reliability
* correctness
* concurrency
*/
import java
class YieldMethod extends Method {
YieldMethod() {
this.getName() = "yield" and
this.getDeclaringType().hasQualifiedName("java.lang", "Thread")
}
}
class YieldMethodAccess extends MethodAccess {
YieldMethodAccess() { this.getMethod() instanceof YieldMethod }
}
from YieldMethodAccess yield
where yield.getCompilationUnit().fromSource()
select yield,
"Do not use Thread.yield(). It is non-portable and will most likely not have the desired effect."