-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathNullMaybe.ql
More file actions
29 lines (27 loc) · 975 Bytes
/
NullMaybe.ql
File metadata and controls
29 lines (27 loc) · 975 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 Dereferenced variable may be null
* @description Dereferencing a variable whose value may be 'null' may cause a
* 'NullPointerException'.
* @kind problem
* @problem.severity warning
* @precision high
* @id java/dereferenced-value-may-be-null
* @tags quality
* reliability
* correctness
* exceptions
* external/cwe/cwe-476
* non-local
*/
import java
private import semmle.code.java.dataflow.SSA
private import semmle.code.java.dataflow.Nullness
from VarAccess access, SsaSourceVariable var, string msg, Expr reason
where
nullDeref(var, access, msg, reason) and
// Exclude definite nulls here, as these are covered by `NullAlways.ql`.
not alwaysNullDeref(var, access) and
// Kotlin enforces this already:
not access.getLocation().getFile().isKotlinSourceFile()
select access, "Variable $@ may be null at this access " + msg + ".", var.getVariable(),
var.getVariable().getName(), reason, "this"