Skip to content

Commit 70e6db3

Browse files
authored
Merge pull request #9902 from aschackmull/java/junit5-assertnotnull
Java: Add support for JUnit5 assertions in the nullness queries.
2 parents 9e7fc17 + cc423af commit 70e6db3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The JUnit5 version of `AssertNotNull` is now recognized, which removes
5+
related false positives in the nullness queries.

java/ql/lib/semmle/code/java/frameworks/Assertions.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* A library providing uniform access to various assertion frameworks.
33
*
44
* Currently supports `org.junit.Assert`, `junit.framework.*`,
5-
* `com.google.common.base.Preconditions`, and `java.util.Objects`.
5+
* `org.junit.jupiter.api.Assertions`, `com.google.common.base.Preconditions`,
6+
* and `java.util.Objects`.
67
*/
78

89
import java
@@ -17,7 +18,11 @@ private newtype AssertKind =
1718
private predicate assertionMethod(Method m, AssertKind kind) {
1819
exists(RefType junit |
1920
m.getDeclaringType() = junit and
20-
(junit.hasQualifiedName("org.junit", "Assert") or junit.hasQualifiedName("junit.framework", _))
21+
(
22+
junit.hasQualifiedName("org.junit", "Assert") or
23+
junit.hasQualifiedName("junit.framework", _) or
24+
junit.hasQualifiedName("org.junit.jupiter.api", "Assertions")
25+
)
2126
|
2227
m.hasName("assertNotNull") and kind = AssertKindNotNull()
2328
or

0 commit comments

Comments
 (0)