java - Got Findbugs issue “NP_NULL_ON_SOME_PATH” when null test is in a separate method. Is this a false alarm? -
i have code similar following snippet:
public void foo(order o) { ... checkinput(o, "some error message"); dosomehing(o.getid()); } private void checkinput(object o, string message) { if (o == null) { throw new someruntimeexception(message); } }
and got findbugs reporting 'np_null_on_some_path' issue.
here description:
there branch of statement that, if executed, guarantees null value dereferenced, generate nullpointerexception when code executed. of course, problem might branch or statement infeasible , null pointer exception can't ever executed; deciding beyond ability of findbugs.
my questions are:
- can treat false positive in example?
- is practice put null test in separate method? actual null check method bit longer sample method don't want repeat code everywhere.
thanks!
it looks findbugs not able detect case, @ least 2.0.2 in eclipse. 1 workaround return value checkerror
, annotate method @nonnull
.
public void foo(order o) { ... dosomehing(checkinput(o, "some error message").getid()); } @nonnull private order checkinput(order o, string message) { if (o == null) { throw new someruntimeexception(message); } ... return o; }
Comments
Post a Comment