Sonar Qube报告称,Objects.inNull始终评估为false,导致生产中的代码构建失败。

huangapple go评论79阅读模式
英文:

Sonar Qube says Objects.inNull always evaluates to false resulting code build fail in production

问题

由于某种原因,声纳报告(客户报告)称下面的 Objects.isNull 总是评估为 false,从而禁用了生产升级。有人能帮我理解为什么客户端声纳(SonarQube)会发生这种情况以及如何解决吗?

Iterable<Sim> result = repository.findAllById(list);

if (Objects.isNull(result)) {  // 声纳认为它总是评估为 false
英文:

For some reason sonar reports(Client reports) that the below Objects.isNull always evaluates false disabling the production upgrade. can someone help me understand why does that happen from the client sonarqube and how to fix?

Iterable&lt;Sim&gt; result = repository.findAllById(list);
		
		if (Objects.isNull(result)) {  // Sonar thinks it always evaluates to false 

答案1

得分: 1

result可能是 empty,但不会是 null,因此 Objects.isNull() 永远不会返回 true

如果在数据库中找不到匹配的数据,则由 iterator() 返回的每个 IteratorhasNext() 都会返回 false

虽然在技术上你可以创建自己的实现,但返回 null 很可能没有意义。

如果你真的想这么做,并且有理由这样做,你可以在同一行添加 //NOSONAR 注释来解释,警告将会消失。

英文:

result may be empty but it will not be null and Objects.isNull() will therefore never return true.

If no mathing data is found in the database, hasNext() returns false for every Iterator returned by iterator().

While you are technically able to create your own implementation, it would likely not make sense to return null.

If you really want to do it and have a reason to, you can add a //NOSONAR comment explaining it in the same line and the warning will disappear.

huangapple
  • 本文由 发表于 2020年9月21日 02:19:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/63982256.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定