Np_Null_On_Some_Path_From_Return_Value

Np_Null_On_Some_Path_From_Return_Value

FindBugs is throwing NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE in the return statement of the below method. Tried to put null check for every value but I'm still unable to fix.

public String toString() {
   String filter = StringUtils.isBlank(this.filter) ? "NONE" : this.filter;

   String res = "";
   if (method != null && method.getName() != null){
      res = method.getName();
   }

   return res;
}
3

1 Answer

Seems that FindBugs is not aware that two separate calls of the getName() return the same value (analyzing this would be quite hard). Seems that your getName() method actually sometimes returns null, so FindBugs internally marks this method return type as @CheckForNull. To remove warning call the method only once. For example like this:

String res = null;
if (method != null)
    res = method.getName();
if (res == null)
    res = "";
return res;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.