Community
Participate
Working Groups
If you turn Windows->Preferences->Java->Compiler->Errors/Warnings->UnnecessaryCode->"redundant null checks" to warning/error, you will get an erroneous error/warning on this code: public static void foobar(String msg) { StringBuffer buffer = null; int startIndex = 0; while (true) { int nextIndex = msg.indexOf('\n', startIndex); if (nextIndex < 0) break; if (buffer == null) buffer = new StringBuffer(); startIndex = nextIndex + 1; } if (buffer == null) // this shows up as a redundant null check System.out.println("Foobar"); } It's true that buffer can be null, but depending on msg it can also be non-null, too.
Released test case NullReferenceTest#466. This bug is fixed with the fix for bug 184298. Resolving as dupe. *** This bug has been marked as a duplicate of bug 184298 ***
Verified for 3.4M2 using I20070917-1800