Skip to content

Commit 26553ce

Browse files
authored
Merge pull request github#9149 from tamasvajk/kotlin-maybe-null
Kotlin: Exclude operands of `NotNullExpr` from NullMaybe query
2 parents d8c2290 + 47ec38c commit 26553ce

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

java/ql/src/Likely Bugs/Nullness/NullMaybe.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ from VarAccess access, SsaSourceVariable var, string msg, Expr reason
2121
where
2222
nullDeref(var, access, msg, reason) and
2323
// Exclude definite nulls here, as these are covered by `NullAlways.ql`.
24-
not alwaysNullDeref(var, access)
24+
not alwaysNullDeref(var, access) and
25+
// Kotlin enforces this already:
26+
not access.getLocation().getFile().isKotlinSourceFile()
2527
select access, "Variable $@ may be null here " + msg + ".", var.getVariable(),
2628
var.getVariable().getName(), reason, "this"

java/ql/test/kotlin/query-tests/NullMaybe/NullMaybe.expected

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Likely Bugs/Nullness/NullMaybe.ql
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fun fn(b: Boolean) {
2+
var d: Double? = null
3+
if (b) {
4+
d = 1.0
5+
}
6+
println(d!!)
7+
}

0 commit comments

Comments
 (0)