参考网站:
Filter file — spotbugs 4.2.0 documentation
FindBugs filter 编写过滤文件配置 - viakiba - OSCHINA - 中文开源技术交流社区
Chapter 8. Filter Files (sourceforge.net)
メモ:
Filter files may be used to include or exclude bug reports for particular classes and methods.
A filter file is an XML document with a top-level FindBugsFilter
element which has some number of Match elements as children. Each Match element represents a predicate which is applied to generated bug instances. Match elements contain children, which are conjuncts of the predicate. In other words, each of the children must be true for the predicate to be true.
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
<Class name="com.foobar.ClassNotToBeAnalyzed" />
</Match>
</FindBugsFilter>
<Bug> 用来指定特殊规则的,规则之间使用逗号做分隔符。
可以使用 -xml或者 Bug descriptions来查看.[https://spotbugs.readthedocs.io/ja/latest/filter.html]
属性pattern:使用pattern作为key来指定匹配。例如:DLS_DEAD_LOCAL_STORE
属性code:使用code作为key来指定匹配。例如:DLS
属性category:最粗颗粒度匹配[category names: CORRECTNESS, MT_CORRECTNESS, BAD_PRACTICICE, PERFORMANCE, STYLE]
如果三个属性都有,则按照三个属性中全部设定的key来匹配
As a backwards compatibility measure, <BugPattern> and <BugCode> elements may be used instead of <Bug> element. Each of these uses a name attribute for specifying accepted values list.
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
<Class name="com.foobar.ClassNotToBeAnalyzed" />
<Bug code="DE,UrF,SIC" pattern="DLS_DEAD_LOCAL_STORE" category="BAD_PRACTICICE" />
</Match>
</FindBugsFilter>
<Priority>
この要素は,警告を特定のバグ信頼度と照合します。
value 属性は,整数値でなければなりません。
1 は信頼度 (High),2 は信頼度 (Medium),3 は信頼度 (Low) の警告と一致します。
<Rank>
匹配錯誤等級。
value 属性は,整数値(1~20)でなければなりません。
1~4:scariest bugs.
5~9:scary bugs.
10~14:troubling bugs.
15~20:concern bugs.
<Package>
对指定package中的类进行警告。
name属性:设定指定package名
matching multiple packages can be achieved easily using regex name match。
<Class>
对特定类进行警告
name属性:指定类名,支持正则匹配
role属性: the class role
等同于Match元素上的class/classregex属性
如果match元素中没有class元素或者class/classregex属性,说明该规则适用于全体类。
<Source>
对指定的文件进行匹配。
name属性:指定特定源文件名,支持正则匹配
<Method>
This element specifies a method
name属性:指定方法名,支持正则匹配
params属性:指定方法参数,使用逗号做分隔符.class names must be fully qualified. (E.g., "java.lang.String" instead of just "String".)
returns属性:指定方法返回值.class names must be fully qualified. (E.g., "java.lang.String" instead of just "String".)
role属性:the method role
<Field>
This element specifies a field.
name属性:指定field name,支持正则匹配。
type属性:通过fieldtype来批量匹配。must be fully qualified type 。
role属性:the field role。
<Local>
specifies a local variable
name属性:指定local variable name,支持正则匹配。
Local variables are variables defined within a method.
<Type>
This element matches warnings associated with a particular type.
The descriptor attribute is used to specify the exact or regex match pattern for type descriptor.
If the descriptor starts with the ~ character the rest of attribute content is interpreted as a Java regular expression.
The role attribute is the class role, and the typeParameters is the type parameters. Both of role and typeParameters are optional attributes.
<Or>
This element combines Match clauses as disjuncts. I.e., you can put two Method elements in an Or clause in order to match either method.
<And>
This element combines Match clauses which both must evaluate to true. I.e., you can put Bug and Confidence elements in an And clause in order to match specific bugs with given confidence only.
<Not>
This element inverts the included child Match. I.e., you can put a Bug element in a Not clause in order to match any bug excluding the given one.