Bug 345332

Summary: Variable not initialized warning
Product: [Eclipse Project] JDT Reporter: Pascal Rapicault <pascal>
Component: CoreAssignee: Ayushman Jain <amj87.iitr>
Status: VERIFIED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, Olivier_Thomann, satyam.kandula, stephan.herrmann
Version: 3.7   
Target Milestone: 3.7 RC1   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Pascal Rapicault CLA 2011-05-10 16:10:30 EDT
The following code complains on the last if statement by saying that that variable handler could have not been initialized. While this is true, I thought that by default the handler variable would be set to null and that as such I should not get the warning since I'm actually checking for null.
Setting the variable to null in the declaration removes the warning.

		ISVNLogEntryHandler handler;
		if (options.searchedString != null)
			handler = new SearchInCommitLog(options.searchedString);
		if (options.getRevisionCmd != null)
			handler = new SearchByRevision(options.getRevisionCmd);
		if (handler == null)
			return;
Comment 1 Pascal Rapicault CLA 2011-05-10 16:10:47 EDT
I'm using I20110507-0800
Comment 2 Ayushman Jain CLA 2011-05-10 16:22:22 EDT
The variable not initialized warning is legal here, and is also given by javac. This is in accordance with rules of definite and indefinite assignment (See chapter 16 of JLS 3.0 - http://java.sun.com/docs/books/jls/).

> I thought that by default the handler variable would be set to null.
An unassigned variable is not assigned by default and the user is expected to assign it in all possible branches of the code, or a compile time error occurs.

I intend to close as INVALID.
Comment 3 Stephan Herrmann CLA 2011-05-10 16:40:16 EDT
(In reply to comment #0)
> [...] I thought that by default the handler variable would be set to null

This would be true only for fields, never for local variables.

I agree with Ayushman that this bug is invalid.
Comment 4 Olivier Thomann CLA 2011-05-10 17:22:19 EDT
Yes, only fields get a default value. Local variables need to be initialized in all possible paths.
Closing as INVALID.
Comment 5 Satyam Kandula CLA 2011-05-12 02:04:51 EDT
Verified for 3.7 RC1