Skip to content

Commit f952293

Browse files
authored
Merge pull request #3526 from aschackmull/java/qltest-fps-nullness-rangeanalyis
Java: Add a few qltest cases for nullness and range analysis FPs.
2 parents 2429e22 + 8cbc01d commit f952293

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,28 @@ public void ex15(Object o1, Object o2) {
220220
return;
221221
}
222222
}
223+
224+
private Object foo16;
225+
226+
private Object getFoo16() {
227+
return this.foo16;
228+
}
229+
230+
public static void ex16(C c) {
231+
int[] xs = c.getFoo16() != null ? new int[5] : null;
232+
if (c.getFoo16() != null) {
233+
xs[0]++; // NPE - false positive
234+
}
235+
}
236+
237+
public static final int MAXLEN = 1024;
238+
239+
public void ex17() {
240+
int[] xs = null;
241+
// loop executes at least once
242+
for (int i = 32; i <= MAXLEN; i *= 2) {
243+
xs = new int[5];
244+
}
245+
xs[0]++; // OK
246+
}
223247
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
| C.java:188:9:188:11 | obj | Variable $@ may be null here because of $@ assignment. | C.java:181:5:181:22 | Object obj | obj | C.java:181:12:181:21 | obj | this |
3232
| C.java:207:9:207:11 | obj | Variable $@ may be null here because of $@ assignment. | C.java:201:5:201:22 | Object obj | obj | C.java:201:12:201:21 | obj | this |
3333
| C.java:219:9:219:10 | o1 | Variable $@ may be null here as suggested by $@ null guard. | C.java:212:20:212:28 | o1 | o1 | C.java:213:9:213:18 | ... == ... | this |
34+
| C.java:233:7:233:8 | xs | Variable $@ may be null here because of $@ assignment. | C.java:231:5:231:56 | int[] xs | xs | C.java:231:11:231:55 | xs | this |
3435
| F.java:11:5:11:7 | obj | Variable $@ may be null here as suggested by $@ null guard. | F.java:8:18:8:27 | obj | obj | F.java:9:9:9:19 | ... == ... | this |
3536
| F.java:17:5:17:7 | obj | Variable $@ may be null here as suggested by $@ null guard. | F.java:14:18:14:27 | obj | obj | F.java:15:9:15:19 | ... == ... | this |

java/ql/test/query-tests/RangeAnalysis/A.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,23 @@ void m13(int n) {
175175
}
176176
}
177177
}
178+
179+
void m14(int[] xs) {
180+
for (int i = 0; i < xs.length + 1; i++) {
181+
if (i == 0 && xs.length > 0) {
182+
xs[i]++; // OK - FP
183+
}
184+
}
185+
}
186+
187+
void m15(int[] xs) {
188+
for (int i = 0; i < xs.length; i++) {
189+
int x = ++i;
190+
int y = ++i;
191+
if (y < xs.length) {
192+
xs[x]++; // OK - FP
193+
xs[y]++; // OK
194+
}
195+
}
196+
}
178197
}

java/ql/test/query-tests/RangeAnalysis/ArrayIndexOutOfBounds.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010
| A.java:111:14:111:21 | ...[...] | This array access might be out of bounds, as the index might be equal to the array length + 1. |
1111
| A.java:122:16:122:23 | ...[...] | This array access might be out of bounds, as the index might be equal to the array length + 3. |
1212
| A.java:134:16:134:23 | ...[...] | This array access might be out of bounds, as the index might be equal to the array length. |
13+
| A.java:182:9:182:13 | ...[...] | This array access might be out of bounds, as the index might be equal to the array length. |
14+
| A.java:192:9:192:13 | ...[...] | This array access might be out of bounds, as the index might be equal to the array length. |

0 commit comments

Comments
 (0)