How to suppress FindBugs warnings for fields or local variables

前端 未结 2 1970
一个人的身影
一个人的身影 2020-12-10 23:54

I would like to suppress FindBugs warnings for specific fields or local variables. FindBugs documents that the Target can be Type, Field, Method, Parameter, Constructor, Pac

相关标签:
2条回答
  • 2020-12-11 00:44

    @SuppressFBWarnings on a field only suppresses findbugs warnings reported for that field declaration, not every warning associated with that field.

    For example, this suppresses the "Field only ever set to null" warning:

    @SuppressFBWarnings("UWF_NULL_FIELD")
    String s = null;
    

    I think the best you can do is isolate the code with the warning into the smallest method you can, then suppress the warning on the whole method.

    Note: @SuppressWarnings was marked deprecated in favor of @SuppressFBWarnings

    0 讨论(0)
  • 2020-12-11 00:50

    Check http://findbugs.sourceforge.net/manual/filter.html#d0e2318 There is a Local tag that can be used with the Method tag. Here you can specify which bug should be excluded for a specific local variable. Example:

    <FindBugsFilter>
      <Match>
            <Class name="<fully-qualified-class-name>" />
            <Method name="<method-name>" />
            <Local name="<local-variable-name-in-above-method>" />
            <Bug pattern="DLS_DEAD_LOCAL_STORE" />
      </Match>
    </FindBugsFilter>
    
    0 讨论(0)
提交回复
热议问题