Bug 149665

Summary: [compiler][null] Unexpected variable might be null warning in finally block
Product: [Eclipse Project] JDT Reporter: Arnaud <ademuyser>
Component: CoreAssignee: Maxime Daniel <maxime_daniel>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: mlists
Version: 3.2   
Target Milestone: 3.3 M3   
Hardware: PC   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 157154    
Attachments:
Description Flags
Fix plus test case. none

Description Arnaud CLA 2006-07-05 09:09:00 EDT
Set Preferences>Java>Compiler>Potential Programming Problems>Null Reference to "Warning".
Then for the following code, JDT reports an unexpected "variable t might be null" warning, it seems to not seeing that t is just checked on left hand of && operator.  finally block inside a for (also while) seems to be important to have this warning.

I'm using build M20060609-1217
Source to reproduce problem:

package jdt.warnings;

public class UnexpectedVariableMightBeNullWarning
{
	private UnexpectedVariableMightBeNullWarning ref1 ;

	public boolean isClose() { return false; }

	public void test()
	{
		for( int j=0; j<10; j++ )
		{
			try {
				j++;
			}			
			finally {
				UnexpectedVariableMightBeNullWarning t = ref1;
				//unexpected "variable t might be null" on right operand of && operator
				//finally block inside for statement seems to be important for that warning.
				if( t!=null && t.isClose() ) {
					
				}
			}
		}
	}

}
Comment 1 Maxime Daniel CLA 2006-07-05 09:54:50 EDT
Reproduced, will investigate.
Comment 2 Maxime Daniel CLA 2006-09-19 08:11:37 EDT
Fixed. Will attach a patch when bug 147118 will be released (cumulative changes for now). Waiting that 3.3 M2 be declared.
Comment 3 Maxime Daniel CLA 2006-09-25 07:01:22 EDT
Created attachment 50811 [details]
Fix plus test case.

Introduced the following notions: cannotBeNull (is isDefinitelyNonNull or isProtectedNonNull) and canOnlyBeNull (is isDefinitelyNull or isProtectedNull) to better catch null related status of locals within finally blocks.
Comment 4 Maxime Daniel CLA 2006-09-25 07:02:20 EDT
Released for 3.3M3.
Comment 5 Olivier Thomann CLA 2006-10-30 14:03:16 EST
Verified for 3.3 M3 using warm-up build I20061030-0010