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

查看:153
本文介绍了有没有一种方法可以抑制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天全站免登陆