diff --git a/java/ql/src/Likely Bugs/Nullness/NullMaybe.ql b/java/ql/src/Likely Bugs/Nullness/NullMaybe.ql index d29ebd7fb898..13a800ae5391 100644 --- a/java/ql/src/Likely Bugs/Nullness/NullMaybe.ql +++ b/java/ql/src/Likely Bugs/Nullness/NullMaybe.ql @@ -21,6 +21,8 @@ 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) + not alwaysNullDeref(var, access) and + // Kotlin enforces this already: + not access.getLocation().getFile().isKotlinSourceFile() select access, "Variable $@ may be null here " + msg + ".", var.getVariable(), var.getVariable().getName(), reason, "this" diff --git a/java/ql/test/kotlin/query-tests/NullMaybe/NullMaybe.expected b/java/ql/test/kotlin/query-tests/NullMaybe/NullMaybe.expected new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/ql/test/kotlin/query-tests/NullMaybe/NullMaybe.qlref b/java/ql/test/kotlin/query-tests/NullMaybe/NullMaybe.qlref new file mode 100644 index 000000000000..ab01473d8e53 --- /dev/null +++ b/java/ql/test/kotlin/query-tests/NullMaybe/NullMaybe.qlref @@ -0,0 +1 @@ +Likely Bugs/Nullness/NullMaybe.ql diff --git a/java/ql/test/kotlin/query-tests/NullMaybe/Test.kt b/java/ql/test/kotlin/query-tests/NullMaybe/Test.kt new file mode 100644 index 000000000000..dc86a0eb34c0 --- /dev/null +++ b/java/ql/test/kotlin/query-tests/NullMaybe/Test.kt @@ -0,0 +1,7 @@ +fun fn(b: Boolean) { + var d: Double? = null + if (b) { + d = 1.0 + } + println(d!!) +}