Community
Participate
Working Groups
Build Identifier: 20100917-0705 I've got some code that boils down to something like this: private Foo getFoo(Var vo) { Foo ack; switch (vo.getBlah()) { default: break; } ack.setBoo(vo == null ? null : vo.getBoo()); return ack; } findbugs correctly reports this as a redundant null check (in the ternary operation). Eclipse doesn't find this with redundant null check turned on to warnings. It seems like it should because vo couldn't be null in setBoo() because the vo.getBlah() would have thrown an NPE in the switch statement. Thanks! Reproducible: Always
I don't see this problem on either 3.6.2 or 3.7 latest I build. Though it does exist on 3.6.1. Since it now seems fixed, closing this as WORKSFORME.
While trying to find the bug by which this issue was fixed I couldn't even reproduce in any version I tried. So, WORKSFORME, seems to be the correct resolution after all. BTW: this is the full source I used: public class Bug { private Foo getFoo(Var vo) { Foo ack; switch (vo.getBlah()) { default: break; } ack.setBoo(vo == null ? null : vo.getBoo()); return ack; } class Foo { void setBoo(String s) {} } class Var{ int getBlah() { return 0; } String getBoo() { return ""; } } } This invocation: $ java -jar ecj-3.6.1.jar -warn:+null Bug.java Gives these problems: ---------- 1. WARNING in Bug.java (at line 2) private Foo getFoo(Var vo) { ^^^^^^^^^^^^^^ The method getFoo(Bug.Var) from the type Bug is never used locally ---------- 2. ERROR in Bug.java (at line 8) ack.setBoo(vo == null ? null : vo.getBoo()); ^^^ The local variable ack may not have been initialized ---------- 3. WARNING in Bug.java (at line 8) ack.setBoo(vo == null ? null : vo.getBoo()); ^^ Null comparison always yields false: The variable vo cannot be null at this location ---------- 4. ERROR in Bug.java (at line 9) return ack; ^^^ The local variable ack may not have been initialized ---------- 4 problems (2 errors, 2 warnings)
Weird. Sorry about that. Maybe it has something to do with my Eclipse install? The upgrade process always seems kind of dubious to me. =) I'll download a new version of 3.6.2, reinstall my plugins, wipe my .metadata and try it again.
Verified for 3.7M6