Files
codeql/java/ql/src/Likely Bugs/Concurrency/WaitOutsideLoop.ql
2019-04-30 10:59:06 -04:00

28 lines
727 B
Plaintext

/**
* @name Wait outside loop
* @description Calling 'wait' outside a loop may result in the program continuing before the
* expected condition is met.
* @kind problem
* @problem.severity error
* @precision low
* @id java/wait-outside-loop
* @tags reliability
* correctness
* concurrency
*/
import java
class WaitMethod extends Method {
WaitMethod() {
this.getName() = "wait" and
this.getDeclaringType().getQualifiedName() = "java.lang.Object"
}
}
from MethodAccess ma
where
ma.getMethod() instanceof WaitMethod and
not exists(LoopStmt s | ma.getEnclosingStmt().getEnclosingStmt*() = s)
select ma, "To avoid spurious wake-ups, 'wait' should only be called inside a loop."