Bug 345332 - Variable not initialized warning
Summary: Variable not initialized warning
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.7 RC1   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-10 16:10 EDT by Pascal Rapicault CLA
Modified: 2011-05-12 02:04 EDT (History)
4 users (show)

See Also:


Attachments

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