Skip to content

Commit 1acbb84

Browse files
committed
Shared/Java: Make the 'isNull' interface slightly prettier.
1 parent ebac171 commit 1acbb84

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

java/ql/lib/semmle/code/java/dataflow/TypeFlow.qll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,12 @@ private module Input implements TypeFlowInput<J::Location> {
133133
not decl.hasImplicitInit() and
134134
not exists(decl.getInit())
135135
)
136-
or
137-
forex(TypeFlowNode mid | joinStep(mid, n) | Make<J::Location, Input>::isNull(mid)) and
136+
}
137+
138+
predicate isExcludedFromNullAnalysis(TypeFlowNode n) {
138139
// Fields that are never assigned a non-null value are probably set by
139140
// reflection and are thus not always null.
140-
not exists(n.asField())
141+
exists(n.asField())
141142
}
142143

143144
predicate exactTypeBase(TypeFlowNode n, RefType t) {

shared/typeflow/codeql/typeflow/TypeFlow.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ signature module TypeFlowInput<LocationSig Location> {
4242
/** Holds if `n` represents a `null` value. */
4343
predicate isNullValue(TypeFlowNode n);
4444

45+
/**
46+
* Holds if `n` should be excluded from the set of null values even if
47+
* the null analysis determines that `n` is always null.
48+
*/
49+
default predicate isExcludedFromNullAnalysis(TypeFlowNode n) { none() }
50+
4551
/** A type. */
4652
class Type {
4753
/** Gets a textual representation of this type. */

shared/typeflow/codeql/typeflow/internal/TypeFlowImpl.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ module TypeFlow<LocationSig Location, TypeFlowInput<Location> I> {
1010
isNullValue(n)
1111
or
1212
exists(TypeFlowNode mid | isNull(mid) and step(mid, n))
13+
or
14+
forex(TypeFlowNode mid | I::joinStep(mid, n) | isNull(mid)) and
15+
not isExcludedFromNullAnalysis(n)
1316
}
1417

1518
/**

0 commit comments

Comments
 (0)