簡體   English   中英

Findbugs Java忽略字段或行

[英]Findbugs Java Ignore Fields or Lines

是否可以為特定字段或行創建Findbugs停用注釋,而不是停用所有方法包含字段的整個檢查?

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value="BEAN_SUPER_CALL_ON_OBJECT",
justification = "I don't want to overwrite the method, but otherwise our equals check issues a warning")
@Override
public boolean equals(final Object obj) {

    // this should not be ignored
    super.test(obj);

    // this should be ignored
    return super.equals(obj);

}

這行不通:

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value="BEAN_SUPER_CALL_ON_OBJECT")
return super.equals(obj);

同樣,這將不起作用:

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value="BEAN_SUPER_CALL_ON_OBJECT")
super.equals(obj);

這可行,但是警告仍然彈出:

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value="BEAN_SUPER_CALL_ON_OBJECT")
boolean ret_val = super.equals(obj);
return ret_val;

對於字段,這是可能的,但對於單行代碼則不能。 根據FindBugs 3.0文檔 ,可以將@SuppressFBWarnings注釋應用於

[目標]類型,字段,方法,參數,構造函數,包

(在edu.umd.cs.findbugs.annotations包中, @SuppressFBWarnings@SuppressWarnings是等效的。)

如您所見, LOCAL_VARIABLEANNOTATION_TYPE不在列表中。 盡管注釋上沒有@Target元素,但是在這兩種情況下,FindBugs會忽略它。

暫無
暫無

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

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