Skip to content

Shared/Java: Add shared Guards library and switch Java to use it. #19573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a0c8491
Java: Add guards-logic qltest with inline expectation.
aschackmull May 1, 2025
994c1f6
Java: Add hasInputFromBlock predicate in BaseSSA.
aschackmull May 2, 2025
1d75008
Shared: Add a shared Guards library inspired by the Java and C# versi…
aschackmull May 2, 2025
14b87f9
Shared: Extend the shared Guards library with support for custom wrap…
aschackmull May 13, 2025
16c5b57
Shared: Extend the shared Guards library with support for exception b…
aschackmull May 15, 2025
c212d0a
Shared: Improve shared guards lib.
aschackmull May 20, 2025
73ae613
Shared: Many tweaks to Guards.
aschackmull May 23, 2025
f772493
Shared: Elaborate qldoc.
aschackmull May 23, 2025
b19bff9
Shared: Switch case guards to be the case statements.
aschackmull May 26, 2025
378209a
Shared: Simplify and improve joins.
aschackmull May 27, 2025
22d5dc9
Shared: Bugfix for unique value implication.
aschackmull Jun 16, 2025
a2778ee
Java: Refactor clearlyNotNullExpr into a base case that does not rely…
aschackmull May 14, 2025
0607fef
Java: Refactor integerGuard.
aschackmull May 19, 2025
cc13193
Java: Replace some references to basicNullGuard.
aschackmull May 21, 2025
5c0dcd9
Java: Switch to the shared Guards library.
aschackmull May 15, 2025
42b1b12
Java: Fix qltests
aschackmull May 27, 2025
d4c897f
Java: Fix perf issue.
aschackmull May 27, 2025
5a34a1a
Shared: Try caching.
aschackmull Jun 16, 2025
73810a6
Java: Fix perf issue.
aschackmull Jun 17, 2025
4645856
Java: document FP
aschackmull Jun 17, 2025
5ddddae
Java: Add change note.
aschackmull Jun 17, 2025
6f4adb8
Shared: address review comments.
aschackmull Jun 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Java: Replace some references to basicNullGuard.
  • Loading branch information
aschackmull committed Jun 26, 2025
commit cc13193cb6a909513294da7312f031381de38293
19 changes: 15 additions & 4 deletions java/ql/lib/semmle/code/java/dataflow/NullGuards.qll
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,21 @@ private Method customNullGuard(int index, boolean retval, boolean isnull) {
}

/**
* `guard` is a guard expression that suggests that `v` might be null.
*
* This is equivalent to `guard = basicNullGuard(sameValue(v, _), _, true)`.
* Holds if `guard` is a guard expression that suggests that `e` might be null.
*/
predicate guardSuggestsExprMaybeNull(Expr guard, Expr e) {
guard.(EqualityTest).hasOperands(e, any(NullLiteral n))
or
exists(MethodCall call |
call = guard and
call.getAnArgument() = e and
nullCheckMethod(call.getMethod(), _, true)
)
}

/**
* Holds if `guard` is a guard expression that suggests that `v` might be null.
*/
predicate guardSuggestsVarMaybeNull(Expr guard, SsaVariable v) {
guard = basicNullGuard(sameValue(v, _), _, true)
guardSuggestsExprMaybeNull(guard, sameValue(v, _))
}
2 changes: 1 addition & 1 deletion java/ql/src/Language Abuse/UselessNullCheck.ql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import semmle.code.java.controlflow.Guards

from Expr guard, Expr e, Expr reason, string msg
where
guard = basicNullGuard(e, _, true) and
guardSuggestsExprMaybeNull(guard, e) and
e = clearlyNotNullExpr(reason) and
(
if reason instanceof Guard
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy