簡體   English   中英

如何正確使用@SuppressFBWarnings忽略printStackTrace findbugs警告

[英]How to use @SuppressFBWarnings correctly to ignore printStackTrace findbugs warning

在我的junit 4測試代碼中,我正在使用包含如下代碼的測試規則:

catch (Throwable t) {
   t.printStackTrace();
   throw t;
}

Findbugs對此有所抱怨,這是正確的-我們的生產代碼中不應這樣做。 但是,在這種情況下,我認為用法是合理的,我嘗試使用@SuppressFBWarnings注釋使findbugs靜音。 但是,兩者都沒有

@SuppressFBWarnings
private void warmUp() throws Throwable {

也不

@SuppressFBWarnings("IMC_IMMATURE_CLASS_PRINTSTACKTRACE")
private void warmUp() throws Throwable {

也不

@SuppressFBWarnings({"IMC_IMMATURE_CLASS_PRINTSTACKTRACE"})
private void warmUp() throws Throwable {

有理想的結果。

如何正確使用@SuppressFBWarnings取消警告?

通過對FindBugs批注使用以下gradle依賴關系:

compile 'com.google.code.findbugs:findbugs-annotations:3.0.1'

這是應該起作用的方法:

@SuppressFBWarnings(value = "IMC_IMMATURE_CLASS_PRINTSTACKTRACE", justification = "Document why this should be ignored here")
private void warmUp() throws Throwable {}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM