Bug 198955 - [compiler][null] False positives on redundant null checks after while(true) loop
Summary: [compiler][null] False positives on redundant null checks after while(true) loop
Status: VERIFIED DUPLICATE of bug 184298
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3.1   Edit
Hardware: PC Linux
: P3 minor (vote)
Target Milestone: 3.4 M2   Edit
Assignee: Maxime Daniel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-08-06 12:38 EDT by Daniel Lew CLA
Modified: 2007-09-18 07:16 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Lew CLA 2007-08-06 12:38:26 EDT
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.
Comment 1 Maxime Daniel CLA 2007-09-10 02:31:46 EDT
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 ***
Comment 2 Jerome Lanneluc CLA 2007-09-18 07:16:51 EDT
Verified for 3.4M2 using I20070917-1800