标签:collections sonarqube guava java
我已经写了这个谓词,而声纳对此有所抱怨.我不确定如何解决此违规问题.请帮忙:
import com.google.common.base.Predicate;
import java.util.Map;
public final class FooPredicate {
private FooPredicate(){}
public static Predicate<Map.Entry<Long,Long>> isFirstElement(final Long o) {
return new Predicate<Map.Entry<Long,Long>>() {
@Override
public boolean apply(Map.Entry<Long,Long> foo) {
return foo.getKey().equals(o);
}
};
}
}
它正在抱怨apply方法的Foo参数.
06001
apply方法定义为采用可为null的值,对此我无能为力.声纳和番石榴不是在这里战斗吗?
> boolean apply(@Nullable
> T input)
>
> Returns the result of applying this predicate to input. This method is
> generally expected, but not absolutely required, to have the following
> properties:
>
> Its execution does not cause any observable side effects.
> The computation is consistent with equals; that is, Objects.equal(a, b) implies that predicate.apply(a) ==
> predicate.apply(b)).
>
> Throws:
> NullPointerException - if input is null and this predicate does not accept null arguments
解决方法:
您正在做foo.getKey().如果foo为null,则将抛出NullPointerException,但您并不是在声明foo不能为null.
在使用前请先检查foo.
if (foo != null) {
return foo.getKey().equals(o);
} else {
return null;
}
标签:collections,sonarqube,guava,java 来源: https://codeday.me/bug/20191028/1955965.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。