Skip to content

Commit d8aae1c

Browse files
committed
Add tests to track nullness by instanceof checks.
1 parent 403899e commit d8aae1c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,4 +324,24 @@ public void corrConds2(Object x, Object y) {
324324
if (x != null) y.hashCode(); // OK
325325
if (y != null) x.hashCode(); // OK
326326
}
327+
328+
public void corrConds3(Object y) {
329+
Object x = null;
330+
if(y instanceof String) {
331+
x = new Object();
332+
}
333+
if(y instanceof String) {
334+
x.hashCode(); // OK
335+
}
336+
}
337+
338+
public void corrConds4(Object y) {
339+
Object x = null;
340+
if(!(y instanceof String)) {
341+
x = new Object();
342+
}
343+
if(!(y instanceof String)) {
344+
x.hashCode(); // OK
345+
}
346+
}
327347
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
| B.java:190:7:190:7 | o | Variable $@ may be null here because of $@ assignment. | B.java:178:5:178:20 | Object o | o | B.java:186:5:186:12 | ...=... | this |
1818
| B.java:279:7:279:7 | a | Variable $@ may be null here because of $@ assignment. | B.java:276:5:276:19 | int[] a | a | B.java:276:11:276:18 | a | this |
1919
| B.java:292:7:292:7 | b | Variable $@ may be null here because of $@ assignment. | B.java:287:5:287:44 | int[] b | b | B.java:287:11:287:43 | b | this |
20+
| B.java:334:7:334:7 | x | Variable $@ may be null here because of $@ assignment. | B.java:329:5:329:20 | Object x | x | B.java:329:12:329:19 | x | this |
21+
| B.java:344:7:344:7 | x | Variable $@ may be null here because of $@ assignment. | B.java:339:5:339:20 | Object x | x | B.java:339:12:339:19 | x | this |
2022
| C.java:9:44:9:45 | a2 | Variable $@ may be null here as suggested by $@ null guard. | C.java:6:5:6:23 | long[][] a2 | a2 | C.java:7:34:7:54 | ... != ... | this |
2123
| C.java:9:44:9:45 | a2 | Variable $@ may be null here because of $@ assignment. | C.java:6:5:6:23 | long[][] a2 | a2 | C.java:6:14:6:22 | a2 | this |
2224
| C.java:10:17:10:18 | a3 | Variable $@ may be null here 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)