From d8aae1c1264d4f36d5dfe9a98f1f2b93a4268265 Mon Sep 17 00:00:00 2001 From: Cornelius Riemenschneider Date: Thu, 21 Nov 2019 18:33:48 +0100 Subject: [PATCH] Add tests to track nullness by instanceof checks. --- java/ql/test/query-tests/Nullness/B.java | 20 +++++++++++++++++++ .../query-tests/Nullness/NullMaybe.expected | 2 ++ 2 files changed, 22 insertions(+) diff --git a/java/ql/test/query-tests/Nullness/B.java b/java/ql/test/query-tests/Nullness/B.java index c0d9171041b..4db5a2f50b5 100644 --- a/java/ql/test/query-tests/Nullness/B.java +++ b/java/ql/test/query-tests/Nullness/B.java @@ -324,4 +324,24 @@ public class B { if (x != null) y.hashCode(); // OK if (y != null) x.hashCode(); // OK } + + public void corrConds3(Object y) { + Object x = null; + if(y instanceof String) { + x = new Object(); + } + if(y instanceof String) { + x.hashCode(); // OK + } + } + + public void corrConds4(Object y) { + Object x = null; + if(!(y instanceof String)) { + x = new Object(); + } + if(!(y instanceof String)) { + x.hashCode(); // OK + } + } } diff --git a/java/ql/test/query-tests/Nullness/NullMaybe.expected b/java/ql/test/query-tests/Nullness/NullMaybe.expected index 5d50a47b9d8..03e24ef04bc 100644 --- a/java/ql/test/query-tests/Nullness/NullMaybe.expected +++ b/java/ql/test/query-tests/Nullness/NullMaybe.expected @@ -17,6 +17,8 @@ | 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 | | 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 | | 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 | +| 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 | +| 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 | | 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 | | 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 | | 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 |