Community
Participate
Working Groups
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() ) { } } } } }
Reproduced, will investigate.
Fixed. Will attach a patch when bug 147118 will be released (cumulative changes for now). Waiting that 3.3 M2 be declared.
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.
Released for 3.3M3.
Verified for 3.3 M3 using warm-up build I20061030-0010