@Nullable和SonarQube'应有条件执行的块可到达'警告 [英] @Nullable and SonarQube 'Conditionally executed blocks should be reachable' warning

查看:516
本文介绍了@Nullable和SonarQube'应有条件执行的块可到达'警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

程序包具有以下package-info.java:

Package has following package-info.java:

@ParametersAreNonnullByDefault
package foo;
import javax.annotation.ParametersAreNonnullByDefault;

类具有以下方法:

private static String toIsoString(@Nullable Instant dateTime) {
  return dateTime == null ? null : dateTime.toString();
}

哪个SonarQube(版本6.2,SonarJava 4.14.0.11784)发出以下警告(squid:S2583):

On which SonarQube (Version 6.2, SonarJava 4.14.0.11784) gives the following warning (squid:S2583):

我如何说服SonarQube代码实际上是正确的?

How can I convince SonarQube that the code is actually correct?

有趣的是,Idea中的SonarLint插件(3.0.0.2041)不会生成相同的警告.

Interestingly, SonarLint plugin (3.0.0.2041) in Idea doesn't generate the same warning.

推荐答案

显然,此问题是由我们使用sonar-scanner而不指定sonar.java.libraries引起的.由于它是多模块Maven项目,因此我们不清楚如何正确指定sonar.java.libraries.

Apparently, this problem was caused by us using sonar-scanner without specifying sonar.java.libraries. Since it's multimodule maven project it wasn't clear to us how to specify sonar.java.libraries correctly.

SonarSource的Nicolas Peru建议我们使用声纳Maven插件而不是sonar-scanner,因为该插件可以访问项目的构建类路径.确实,这为我们解决了这个问题.

Nicolas Peru, from SonarSource, suggested that we should use sonar maven plugin, instead of sonar-scanner, as the plugin has access to build classpath of the project. Indeed that solved this problem for us.

这篇关于@Nullable和SonarQube'应有条件执行的块可到达'警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆