Java: Add support for JUnit5 assertions in the nullness queries.

This commit is contained in:
Anders Schack-Mulligen
2022-07-27 10:20:47 +02:00
parent 43ae5d4285
commit cc423af8f1
2 changed files with 12 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
category: minorAnalysis
---
* The JUnit5 version of `AssertNotNull` is now recognized, which removes
related false positives in the nullness queries.

View File

@@ -2,7 +2,8 @@
* A library providing uniform access to various assertion frameworks.
*
* Currently supports `org.junit.Assert`, `junit.framework.*`,
* `com.google.common.base.Preconditions`, and `java.util.Objects`.
* `org.junit.jupiter.api.Assertions`, `com.google.common.base.Preconditions`,
* and `java.util.Objects`.
*/
import java
@@ -17,7 +18,11 @@ private newtype AssertKind =
private predicate assertionMethod(Method m, AssertKind kind) {
exists(RefType junit |
m.getDeclaringType() = junit and
(junit.hasQualifiedName("org.junit", "Assert") or junit.hasQualifiedName("junit.framework", _))
(
junit.hasQualifiedName("org.junit", "Assert") or
junit.hasQualifiedName("junit.framework", _) or
junit.hasQualifiedName("org.junit.jupiter.api", "Assertions")
)
|
m.hasName("assertNotNull") and kind = AssertKindNotNull()
or