FindBugs在以下方法的return语句中抛出NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE。试图对每个值进行空检查但仍无法修复。
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;
}
答案 0 :(得分:3)
似乎FindBugs不知道getName()
的两个单独调用返回相同的值(分析这将是非常困难的)。似乎您的getName()
方法实际上有时会返回null,因此FindBugs在内部将此方法返回类型标记为@CheckForNull
。要删除警告,只需调用一次该方法。例如:
String res = null;
if (method != null)
res = method.getName();
if (res == null)
res = "";
return res;