File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
java/ql/test/query-tests/Nullness Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -408,4 +408,32 @@ public void bitwise(Object x, boolean b) {
408408 x .hashCode (); // NPE
409409 }
410410 }
411+
412+ public void corrCondLoop1 (boolean a []) {
413+ Object x = new Object ();
414+ for (int i = 0 ; i < a .length ; i ++) {
415+ boolean b = a [i ];
416+ if (b ) {
417+ x = null ;
418+ }
419+ if (!b ) {
420+ x .hashCode (); // NPE - false negative
421+ }
422+ // flow can loop around from one iteration to the next
423+ }
424+ }
425+
426+ public void corrCondLoop2 (boolean a []) {
427+ for (int i = 0 ; i < a .length ; i ++) {
428+ // x is local to the loop iteration and thus cannot loop around and reach the sink
429+ Object x = new Object ();
430+ boolean b = a [i ];
431+ if (b ) {
432+ x = null ;
433+ }
434+ if (!b ) {
435+ x .hashCode (); // OK
436+ }
437+ }
438+ }
411439}
You can’t perform that action at this time.
0 commit comments