Findbugs中的過濾

2017-02-14 09:32:40來源:威易網(wǎng)作者:joe

我們部分產(chǎn)品中發(fā)現(xiàn)Findbugs檢查有以下錯誤:Type MS_SHOULD_BE_FINAL

我們部分產(chǎn)品中發(fā)現(xiàn)Findbugs檢查有以下錯誤:

Type MS_SHOULD_BE_FINAL

This static field public but not final, and could be changed by malicious code or by accident from another package. The field could be made final to avoid this vulnerability.

這個類型的錯誤屬于設(shè)計上不夠嚴(yán)謹(jǐn),但由于歷史代碼修改比較多,所以我們可以對這個錯誤告警進(jìn)行過濾。

具體方法如下:

增加一個過濾文件

我這里命名為:findbugs-exclude.xml

<FindBugsFilter>
    <Match>
        <Bug pattern="MS_SHOULD_BE_FINAL" />
    </Match>
</FindBugsFilter>

修改pom.xml

在findbugs中增加配置:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>findbugs-maven-plugin</artifactId>
    <version>3.0.4</version>
    <configuration>
         <excludeFilterFile>findbugs-exclude.xml</excludeFilterFile>
    </configuration>
</plugin>

現(xiàn)在這個問題就不會再告警了。

不過,我們還是要嚴(yán)謹(jǐn)?shù)膶Υ鼺indbugs和PMD提醒我們的問題。

關(guān)鍵詞:Findbugs

相關(guān)閱讀: