Skip to content

Commit 143fc7d

Browse files
committed
Java: Add nullness test covering known FP.
1 parent 6f0d46d commit 143fc7d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,4 +557,23 @@ public void rangetest(int n) {
557557
if (n > 100) s.hashCode(); // OK
558558
if (n == 42) s.hashCode(); // OK
559559
}
560+
561+
public void testFinally2(int[] xs) {
562+
String s = null;
563+
int i = 0;
564+
while (true) {
565+
try {
566+
int x = xs[i++];
567+
if (x == 0) {
568+
s = "foo";
569+
break;
570+
} else if (x == 1) {
571+
continue;
572+
}
573+
} finally {
574+
}
575+
}
576+
s.hashCode(); // Spurious NPE - false positive
577+
// CFG reachability does not distinguish abrupt successors
578+
}
560579
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
| B.java:516:5:516:5 | o | Variable $@ may be null at this access as suggested by $@ null guard. | B.java:511:25:511:32 | o | o | B.java:512:22:512:30 | ... == ... | this |
2828
| B.java:535:7:535:8 | s2 | Variable $@ may be null at this access because of $@ assignment. | B.java:523:5:523:21 | String s2 | s2 | B.java:523:12:523:20 | s2 | this |
2929
| B.java:537:5:537:6 | s1 | Variable $@ may be null at this access because of $@ assignment. | B.java:522:5:522:21 | String s1 | s1 | B.java:522:12:522:20 | s1 | this |
30+
| B.java:576:5:576:5 | s | Variable $@ may be null at this access because of $@ assignment. | B.java:562:5:562:20 | String s | s | B.java:562:12:562:19 | s | this |
3031
| 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 |
3132
| 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 |
3233
| 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)