Bug 29501

Summary: Uninitialized variable warning does not analyze the program thoroughly enough
Product: [Eclipse Project] JDT Reporter: Oyvind Harboe <oyvind.harboe>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: RESOLVED WONTFIX QA Contact:
Severity: enhancement    
Priority: P3    
Version: 2.1   
Target Milestone: 2.1 M5   
Hardware: All   
OS: All   
Whiteboard:

Description Oyvind Harboe CLA 2003-01-15 02:23:47 EST
The warning below shows up when it shouldn't, the first iteration of the code 
loop always executes.

Similar cases can be constructed with if() statements.



/**
 * @author oharboe
 */
public class Test
{

	public int foo()
	{
		int t;
		for (int i=0; i<10; i++)
		{
			t=1*i;
		}
		// The local variable t may not have been initialized		
		return t;
	}
}
Comment 1 Philipe Mulet CLA 2003-01-15 04:56:55 EST
This is a consequence of the conservative definite assignment rules described 
in JLS (chapter 16).

In brief, the analysis doesn't look deep enough to figure that it will perform 
at least one iteration in the loop (it could since only constants are involved, 
but this is the conservative spec we implement).

Javac and Jikes behave in the same way.
Comment 2 Philipe Mulet CLA 2003-01-15 04:58:08 EST
Closing, following the JLS.