Skip to content

Commit 92f32a1

Browse files
committed
Add tests for nullness tracking by comparing variables.
1 parent 3e5324e commit 92f32a1

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,31 @@ public void corrConds4(Object y) {
344344
x.hashCode(); // OK
345345
}
346346
}
347+
348+
public void corrConds5(Object y, Object z) {
349+
Object x = null;
350+
if(y == z) {
351+
x = new Object();
352+
}
353+
if(y == z) {
354+
x.hashCode(); // OK
355+
}
356+
357+
Object x2 = null;
358+
if(y != z) {
359+
x2 = new Object();
360+
}
361+
if(y != z) {
362+
x2.hashCode(); // OK
363+
}
364+
365+
Object x3 = null;
366+
if(y != z) {
367+
x3 = new Object();
368+
}
369+
if(!(y == z)) {
370+
x3.hashCode(); // OK
371+
}
372+
}
373+
347374
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
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:354:7:354:7 | x | Variable $@ may be null here because of $@ assignment. | B.java:349:5:349:20 | Object x | x | B.java:349:12:349:19 | x | this |
21+
| B.java:362:7:362:8 | x2 | Variable $@ may be null here because of $@ assignment. | B.java:357:5:357:21 | Object x2 | x2 | B.java:357:12:357:20 | x2 | this |
22+
| B.java:370:7:370:8 | x3 | Variable $@ may be null here because of $@ assignment. | B.java:365:5:365:21 | Object x3 | x3 | B.java:365:12:365:20 | x3 | this |
2023
| 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 |
2124
| 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 |
2225
| 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)