-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathThreadSafety.ql
More file actions
30 lines (28 loc) · 883 Bytes
/
ThreadSafety.ql
File metadata and controls
30 lines (28 loc) · 883 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 Thread safety
* @description Calling Swing methods from a thread other than the event-dispatching thread may
* result in multi-threading errors.
* @kind problem
* @problem.severity warning
* @precision low
* @id java/swing-thread-safety
* @tags reliability
* maintainability
* frameworks/swing
*/
import java
from MethodCall ma, Method m, MainMethod main
where
ma.getQualifier().getType().getCompilationUnit().getPackage().getName().matches("javax.swing%") and
(
m.hasName("show") and m.hasNoParameters()
or
m.hasName("pack") and m.hasNoParameters()
or
m.hasName("setVisible") and m.getNumberOfParameters() = 1
) and
ma.getMethod() = m and
ma.getEnclosingCallable() = main
select ma,
"Call to swing method in " + main.getDeclaringType().getName() +
" needs to be performed in Swing event thread."