我认为FindBugs(2.0.2)和Sonar(3.7.3)的错误肯定是关于通过静态编织EclipseLink(2.5.1)JPA实体生成的代码。具体来说,我看到多次出现
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生成的代码的这些警告,而不必全局禁用规则或完全排除对实体的分析?
答案 0 :(得分:4)
非常好的问题!由于您的问题源自FindBugs,因此您可以使用FindBugs exclusion filters来解决此问题。特别是,请查看<Method>
排除。您可以指定与实体类中的getter和setter的方法名称匹配的正则表达式,例如
<Method name="~_persistence_[gs]et" />
所有形式的FindBugs都可以使用这样的过滤器文件,包括Eclipse插件和SonarQube。例如,使用SonarQube ant任务,您可以将属性sonar.findbugs.excludesFilters
设置为FindBugs排除文件的绝对路径。
答案 1 :(得分:0)