Skip to content

Commit 1c72437

Browse files
committed
Java: More nullness qltests.
1 parent ba252cb commit 1c72437

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

java/ql/test/query-tests/Nullness/B.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,4 +471,29 @@ public void loopCorrTest2(boolean[] a) {
471471
}
472472
}
473473
}
474+
475+
public void loopCorrTest3(String[] ss) {
476+
Object x = null;
477+
Object t = null;
478+
for (String s : ss) {
479+
if (t == null) {
480+
t = s;
481+
} else {
482+
if (t instanceof String) {
483+
x = new Object();
484+
t = new Object();
485+
}
486+
// correctly guarded by t: null -> String -> Object
487+
x.hashCode(); // Spurious NPE - false positive
488+
}
489+
}
490+
}
491+
492+
public void initCorr(boolean b) {
493+
Object o2 = b ? null : "";
494+
if (b)
495+
o2 = "";
496+
else
497+
o2.hashCode(); // OK
498+
}
474499
}

java/ql/test/query-tests/Nullness/NullMaybe.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
| B.java:408:7:408:7 | x | Variable $@ may be null at this access as suggested by $@ null guard. | B.java:374:23:374:30 | x | x | B.java:375:23:375:31 | ... != ... | this |
2121
| B.java:448:9:448:9 | x | Variable $@ may be null at this access because of $@ assignment. | B.java:442:5:442:28 | Object x | x | B.java:446:9:446:16 | ...=... | this |
2222
| B.java:465:9:465:9 | x | Variable $@ may be null at this access because of $@ assignment. | B.java:458:5:458:28 | Object x | x | B.java:470:9:470:16 | ...=... | this |
23+
| B.java:487:9:487:9 | x | Variable $@ may be null at this access because of $@ assignment. | B.java:476:5:476:20 | Object x | x | B.java:476:12:476:19 | x | this |
2324
| C.java:9:44:9:45 | a2 | Variable $@ may be null at this access as suggested by $@ null guard. | C.java:6:5:6:23 | long[][] a2 | a2 | C.java:7:34:7:54 | ... != ... | this |
2425
| C.java:9:44:9:45 | a2 | Variable $@ may be null at this access because of $@ assignment. | C.java:6:5:6:23 | long[][] a2 | a2 | C.java:6:14:6:22 | a2 | this |
2526
| C.java:10:17:10:18 | a3 | Variable $@ may be null at this access as suggested by $@ null guard. | C.java:8:5:8:21 | long[] a3 | a3 | C.java:9:38:9:58 | ... != ... | this |

0 commit comments

Comments
 (0)