mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Java: Add support for JUnit5 assertions in the nullness queries.
This commit is contained in:
5
java/ql/lib/change-notes/2022-07-27-nullness-junit5.md
Normal file
5
java/ql/lib/change-notes/2022-07-27-nullness-junit5.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
* The JUnit5 version of `AssertNotNull` is now recognized, which removes
|
||||
related false positives in the nullness queries.
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user