Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;
}
like image 630
Balasubramanian Ramar Avatar asked Dec 11 '15 11:12

Balasubramanian Ramar


1 Answers

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;
like image 75
Tagir Valeev Avatar answered Sep 19 '22 14:09

Tagir Valeev