我还在SpotBugs issue tracker上问了这个问题。
很抱歉,仍在使用FindBugs,但积压的工单中有一个升级到SpotBugs的票证,据我了解,配置是相同的,我只需要更新groupId
,artifactId
和version
。
这是我的pom.xml
的作品:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>${findbugs.version}</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<effort>Max</effort>
<threshold>High</threshold>
<xmlOutput>true</xmlOutput>
<failOnError>true</failOnError>
<excludeFilterFile>findbugs-filter.xml</excludeFilterFile>
<skip>false</skip>
<plugins>
<plugin>
<groupId>com.mebigfatguy.fb-contrib</groupId>
<artifactId>fb-contrib</artifactId>
<version>${fb-contrib.version}</version>
</plugin>
<plugin>
<groupId>com.h3xstream.findsecbugs</groupId>
<artifactId>findsecbugs-plugin</artifactId>
<version>${findsecbugs.version}</version>
</plugin>
</plugins>
</configuration>
</plugin>
我运行以下命令:
mvn verify
这将生成文件target/findbugsXML.xml
,其中包含BugInstances
,如下所示:
<BugCollection sequence='0' release='' analysisTimestamp='1554129043559' version='3.0.1' timestamp='1554129041000'>
<BugInstance instanceOccurrenceNum='0' instanceHash='8dc725917956f30f9b8ab828a70d6420' rank='16' abbrev='Bx'
category='PERFORMANCE' priority='1' type='DM_BOXED_PRIMITIVE_TOSTRING' instanceOccurrenceMax='0'>
<ShortMessage>Method allocates a boxed primitive just to call toString</ShortMessage>
<LongMessage>Primitive boxed just to call toString in com.itextpdf.barcodes.Barcode128.setCode(String)
</LongMessage>
<Class classname='com.itextpdf.barcodes.Barcode128' primary='true'>
<SourceLine classname='com.itextpdf.barcodes.Barcode128' start='67' end='900'
sourcepath='com/itextpdf/barcodes/Barcode128.java' sourcefile='Barcode128.java'>
<Message>At Barcode128.java:[lines 67-900]</Message>
</SourceLine>
<Message>In class com.itextpdf.barcodes.Barcode128</Message>
</Class>
<Method isStatic='false' classname='com.itextpdf.barcodes.Barcode128' signature='(Ljava/lang/String;)V'
name='setCode' primary='true'>
<SourceLine endBytecode='579' classname='com.itextpdf.barcodes.Barcode128' start='682' end='718'
sourcepath='com/itextpdf/barcodes/Barcode128.java' sourcefile='Barcode128.java'
startBytecode='0'></SourceLine>
<Message>In method com.itextpdf.barcodes.Barcode128.setCode(String)</Message>
</Method>
<Method isStatic='false' role='METHOD_CALLED' classname='java.lang.Integer' signature='()Ljava/lang/String;'
name='toString'>
<SourceLine endBytecode='31' classname='java.lang.Integer' start='935' end='935'
sourcepath='java/lang/Integer.java' sourcefile='Integer.java' startBytecode='0'></SourceLine>
<Message>Called method Integer.toString()</Message>
</Method>
<Method isStatic='true' role='SHOULD_CALL' classname='java.lang.Integer' signature='(I)Ljava/lang/String;'
name='toString'>
<Message>Should call Integer.toString(int) instead</Message>
</Method>
<SourceLine endBytecode='135' classname='com.itextpdf.barcodes.Barcode128' start='699' end='699'
sourcepath='com/itextpdf/barcodes/Barcode128.java' sourcefile='Barcode128.java' startBytecode='135'
primary='true'>
<Message>At Barcode128.java:[line 699]</Message>
</SourceLine>
</BugInstance>
...
</BugCollection>
我想将此报告用作基准,以防止新的Findbugs错误蔓延,因此我想将此报告转换为excludeFilterFile
。
对于以上代码段,语法应变为:
<FindBugsFilter>
<Match>
<Class name="com.itextpdf.barcodes.Barcode128" />
<Method name="setCode" params="java.lang.String" returns="void" />
<Bug pattern="DM_BOXED_PRIMITIVE_TOSTRING" />
</Match>
</FindBugsFilter>
根据this Stack Overflow answer,我应该做的是:
target/findbugsXML.xml
(已完成)mvn findbugs:gui
findbugsXml.xml
文件findbugs-filter.xml
这样做时,我得到一个包含以下内容的findbugs-filter.xml
文件:
<FindBugsFilter></FindBugsFilter>
那是一个空的过滤器文件。
那么我在这里做错了什么?生成过滤器文件的正确方法是什么?我希望我不必手动进行操作,因为实际上有数百种警告。