Community
Participate
Working Groups
This snippet causes null analysis to raise an incorrect warning. It could probably be slightly more minimal, but this actually makes sense. private final static class Node { public Node parent; public Node sibling; public Node child; } public void nullAnalysisBug(Node node) { Node cur = node; do { if (null != cur.child) // INCORRECT -> warning: The variable cur may be null cur = cur.child; else if (null != cur.sibling) cur = cur.sibling; else if (null != cur.parent) cur = cur.parent.sibling; else cur = null; // B } while (cur != null); } There are two workarounds: A. Transforming the loop into a while loop silences the warning, at the cost of an additional comparison at runtime. B. Transforming the final else statement into a 'break' also averts the warning:
Agreed. Following shorter test case should remove any doubt about it: public class X { String f; void foo (boolean b) { X x = new X(); do { System.out.println(x.f); // yields may be null, whereas it is not first // time, and is protected by the test thereafter if (b) { x = null; } } while (x != null); } } Added (inactive) test NullReferenceTest#613.
Created attachment 50447 [details] Suggested fix plus activated test case Mistakenly used the action flow info in input for the looping context late check. Must use the upstream flow instead. Waiting for 3.3 M2 to be declared before committing.
Released for 3.3M3.
Verified for 3.3 M3 using warm-up build I20061030-0010
Changing OS from Mac OS to Mac OS X as per bug 185991