-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathFutileSynchOnField.ql
More file actions
29 lines (25 loc) · 938 Bytes
/
FutileSynchOnField.ql
File metadata and controls
29 lines (25 loc) · 938 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
/**
* @name Futile synchronization on field
* @description Synchronizing on a field and updating that field while the lock is held is unlikely
* to provide the desired thread safety.
* @kind problem
* @problem.severity error
* @precision medium
* @id java/unsafe-sync-on-field
* @tags quality
* reliability
* correctness
* concurrency
* language-features
* external/cwe/cwe-662
*/
import java
private Field synchField(SynchronizedStmt s) { result = s.getExpr().(VarAccess).getVariable() }
private Field assignmentToField(Assignment a) { result = a.getDest().(VarAccess).getVariable() }
from SynchronizedStmt s, Field f, Assignment a
where
synchField(s) = f and
assignmentToField(a) = f and
a.getEnclosingStmt().getEnclosingStmt*() = s
select a, "Synchronization on field $@ in futile attempt to guard that field.", f,
f.getDeclaringType().getName() + "." + f.getName()