Community
Participate
Working Groups
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;
I'm using I20110507-0800
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.
(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.
Yes, only fields get a default value. Local variables need to be initialized in all possible paths. Closing as INVALID.
Verified for 3.7 RC1