-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathCondExprTypes.ql
More file actions
29 lines (25 loc) · 893 Bytes
/
CondExprTypes.ql
File metadata and controls
29 lines (25 loc) · 893 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 Type mismatch in conditional expression
* @description Using the '(p?e1:e2)' operator with different primitive types for the second and
* third operands may cause unexpected results.
* @kind problem
* @problem.severity warning
* @precision low
* @id java/type-mismatch-in-conditional
* @tags reliability
* correctness
*/
import java
class CharType extends PrimitiveType {
CharType() { this.hasName("char") }
}
private Type getABranchType(ConditionalExpr ce) { result = ce.getABranchExpr().getType() }
from ConditionalExpr ce
where
getABranchType(ce) instanceof CharType and
exists(Type t | t = getABranchType(ce) |
t instanceof PrimitiveType and
not t instanceof CharType
)
select ce, "Mismatch between types of branches: $@ and $@.", ce.getThen(),
ce.getThen().getType().getName(), ce.getElse(), ce.getElse().getType().getName()