有没有办法抑制 FindBugs 对静态编织生成的代码产生警告? [英] Is there a way to suppress FindBugs from generating warnings on code generated by static weaving?

查看:31
本文介绍了有没有办法抑制 FindBugs 对静态编织生成的代码产生警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为 FindBugs (2.0.2) 和 Sonar (3.7.3) 对通过 EclipseLink (2.5.1) JPA 实体的静态编织生成的代码的误报.具体来说,我看到多次出现

I'm getting what I think are false positives from FindBugs (2.0.2) and Sonar (3.7.3) on code that is being generated via static weaving of EclipseLink (2.5.1) JPA entities. Specifically, I am seeing multiple occurrences of

ES_COMPARING_PARAMETER_STRING_WITH_EQ
Comparison of String parameter using == or != in com.test.domain.MyEntity._persistence_set(String, Object)

URV_INHERITED_METHOD_WITH_RELATED_TYPES
Inherited method com.test.domain.MyEntity._persistence_get(String) returns more specific type of object than declared

有没有办法消除 EclipseLink 生成的代码的这些警告,而不必全局禁用规则或完全排除对实体的分析?

Is there a way to eliminate these warnings for the code generated by EclipseLink without having to globally disable the rules or exclude analysis on the entities entirely?

推荐答案

非常好的问题!由于您的问题源于 FindBugs,您可以使用 FindBugs 排除过滤器 来解决此问题.特别是,看看 <Method> 排除.您可以在实体类中指定一个与您的 getter 和 setter 的方法名称匹配的正则表达式,例如

Very good question! Since your issues originate with FindBugs, you can use FindBugs exclusion filters to address this. Especially, take a look at the <Method> exclusion. You can specify a regex that matches the method names of your getters and setters in the entity classes, such as

<Method name="~_persistence_[gs]et" />

所有形式的 FindBugs 都可以使用这样的过滤器文件,包括 Eclipse 插件和 SonarQube.例如,使用 SonarQube ant 任务,您可以将属性 sonar.findbugs.excludesFilters 设置为 FindBugs 排除文件的绝对路径.

Such a filter file can be used by all forms of FindBugs, including the Eclipse plugin and SonarQube. For example, using the SonarQube ant task, you can set the property sonar.findbugs.excludesFilters to the absolute path to the FindBugs exclusion file.

这篇关于有没有办法抑制 FindBugs 对静态编织生成的代码产生警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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