Bug 149665 - [compiler][null] Unexpected variable might be null warning in finally block
Summary: [compiler][null] Unexpected variable might be null warning in finally block
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.3 M3   Edit
Assignee: Maxime Daniel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 157154
  Show dependency tree
 
Reported: 2006-07-05 09:09 EDT by Arnaud CLA
Modified: 2006-10-30 14:03 EST (History)
1 user (show)

See Also:


Attachments
Fix plus test case. (10.72 KB, patch)
2006-09-25 07:01 EDT, Maxime Daniel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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