java - 如何在避免 Sonar 规则鱿鱼 :S2175 的同时检查 List<Class> 是否包含类

标签 java sonarqube

我有一个允许的自定义注释列表,我正在尝试通过调用列表中的 contains 方法来检查是否允许特定注释。 这有效,但 Sonar 提示规则 squid:S2175。它说:

A "List<Class>" cannot contain a "Class"

A couple Collection methods can be called with arguments of an incorrect type, but doing so is pointless and likely the result of using the wrong argument. This rule will raise an issue when the type of the argument to List.contains or List.remove is unrelated to the type used for the list declaration.

我该如何解决这个问题?

这是一个最小的例子:

private boolean testClassContains(){
        final List<Class<? extends Annotation>> annotations = Arrays.asList(MyAnnotation.class,YourAnnotation.class);

        return annotations.contains(YourAnnotation.class);
}

最佳答案

1) 首先确保您使用的是最新版本的 SONarQUbe/SonarJava 插件

2) SonarQube 是人写的软件,所以可能会有错误。比如类似案例https://groups.google.com/forum/#!topic/sonarqube/qyOOOZORBNs 我建议你在他们的 Jira 中提交问题。

3) 同时,压制它。有理有据,压抑不是恶

关于java - 如何在避免 Sonar 规则鱿鱼 :S2175 的同时检查 List<Class> 是否包含类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55812657/

相关文章:

SonarQube 不支持并行执行 - 如何在连续管道中使用

java - 将 double 转换为 32 位表示(和反向过程)

java - 存储类的 JSON 以及对同一类的对象的引用

java - java和php可以集成吗

android - Sonarqube 整体覆盖范围与 jacoco 报告覆盖范围不匹配

java - 需要在 public void testWhenRespWriterIsNull() 内进行断言 throws IOException

java - 为什么文件在同一个包中却需要导入?

java - 如何创建 Liferay hook 以扩展购物车 portlet 的功能

javascript - Jenkins sonarqube 插件无法分析文件

maven - SonarQube - Java 堆错误