Java: More nullness qltests.

This commit is contained in:
Anders Schack-Mulligen
2025-08-14 14:14:54 +02:00
parent ba252cb5cf
commit 1c724372f2
2 changed files with 26 additions and 0 deletions

View File

@@ -471,4 +471,29 @@ public class B {
}
}
}
public void loopCorrTest3(String[] ss) {
Object x = null;
Object t = null;
for (String s : ss) {
if (t == null) {
t = s;
} else {
if (t instanceof String) {
x = new Object();
t = new Object();
}
// correctly guarded by t: null -> String -> Object
x.hashCode(); // Spurious NPE - false positive
}
}
}
public void initCorr(boolean b) {
Object o2 = b ? null : "";
if (b)
o2 = "";
else
o2.hashCode(); // OK
}
}

View File

@@ -20,6 +20,7 @@
| B.java:408:7:408:7 | x | Variable $@ may be null at this access as suggested by $@ null guard. | B.java:374:23:374:30 | x | x | B.java:375:23:375:31 | ... != ... | this |
| B.java:448:9:448:9 | x | Variable $@ may be null at this access because of $@ assignment. | B.java:442:5:442:28 | Object x | x | B.java:446:9:446:16 | ...=... | this |
| B.java:465:9:465:9 | x | Variable $@ may be null at this access because of $@ assignment. | B.java:458:5:458:28 | Object x | x | B.java:470:9:470:16 | ...=... | this |
| B.java:487:9:487:9 | x | Variable $@ may be null at this access because of $@ assignment. | B.java:476:5:476:20 | Object x | x | B.java:476:12:476:19 | x | this |
| 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 |
| 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 |
| 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 |