Java: Add a few qltest cases for nullness and range analysis FPs.

This commit is contained in:
Anders Schack-Mulligen
2020-05-20 10:44:15 +02:00
parent 0c081a8e87
commit 8cbc01d49b
4 changed files with 46 additions and 0 deletions

View File

@@ -220,4 +220,28 @@ public class C {
return;
}
}
private Object foo16;
private Object getFoo16() {
return this.foo16;
}
public static void ex16(C c) {
int[] xs = c.getFoo16() != null ? new int[5] : null;
if (c.getFoo16() != null) {
xs[0]++; // NPE - false positive
}
}
public static final int MAXLEN = 1024;
public void ex17() {
int[] xs = null;
// loop executes at least once
for (int i = 32; i <= MAXLEN; i *= 2) {
xs = new int[5];
}
xs[0]++; // OK
}
}

View File

@@ -31,5 +31,6 @@
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |

View File

@@ -175,4 +175,23 @@ public class A {
}
}
}
void m14(int[] xs) {
for (int i = 0; i < xs.length + 1; i++) {
if (i == 0 && xs.length > 0) {
xs[i]++; // OK - FP
}
}
}
void m15(int[] xs) {
for (int i = 0; i < xs.length; i++) {
int x = ++i;
int y = ++i;
if (y < xs.length) {
xs[x]++; // OK - FP
xs[y]++; // OK
}
}
}
}

View File

@@ -10,3 +10,5 @@
| 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. |
| 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. |
| A.java:134:16:134:23 | ...[...] | This array access might be out of bounds, as the index might be equal to the array length. |
| A.java:182:9:182:13 | ...[...] | This array access might be out of bounds, as the index might be equal to the array length. |
| A.java:192:9:192:13 | ...[...] | This array access might be out of bounds, as the index might be equal to the array length. |