From 23aac0ac5140f004103d958496ff83dda0cfedf1 Mon Sep 17 00:00:00 2001 From: Anders Schack-Mulligen Date: Tue, 5 Aug 2025 13:49:51 +0200 Subject: [PATCH] Java: document nullness false negative as qltest --- java/ql/test/query-tests/Nullness/B.java | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/java/ql/test/query-tests/Nullness/B.java b/java/ql/test/query-tests/Nullness/B.java index 0ab6d58dbaeb..99bd6f4a1bae 100644 --- a/java/ql/test/query-tests/Nullness/B.java +++ b/java/ql/test/query-tests/Nullness/B.java @@ -408,4 +408,32 @@ public void bitwise(Object x, boolean b) { x.hashCode(); // NPE } } + + public void corrCondLoop1(boolean a[]) { + Object x = new Object(); + for (int i = 0; i < a.length; i++) { + boolean b = a[i]; + if (b) { + x = null; + } + if (!b) { + x.hashCode(); // NPE - false negative + } + // flow can loop around from one iteration to the next + } + } + + public void corrCondLoop2(boolean a[]) { + for (int i = 0; i < a.length; i++) { + // x is local to the loop iteration and thus cannot loop around and reach the sink + Object x = new Object(); + boolean b = a[i]; + if (b) { + x = null; + } + if (!b) { + x.hashCode(); // OK + } + } + } }