DLS_DEAD_LOCAL_STORE SuppressWarnings FindBugs误报

Gar*_*eld 7 java findbugs suppress-warnings spring-annotations

我正试图消除DLS_DEAD_LOCAL_STORE的误报

这是我到目前为止所尝试的:

@SuppressWarnings("DLS_DEAD_LOCAL_STORE")
Run Code Online (Sandbox Code Playgroud)

@edu.umd.cs.findbugs.annotations.SuppressWarnings("DLS_DEAD_LOCAL_STORE")

(基于SuppressWarnings不适用于FindBugs)

@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "DLS_DEAD_LOCAL_STORE", justification = "please go away")

基于http://osdir.com/ml/java-findbugs-general/2010-06/msg00017.html

但是这些选择都没有帮助.请指教.使用Eclipse Indigo.

Seb*_*etz 7

我对这段代码有同样的问题:

@Test
public void testSomething() {

    @SuppressWarnings("unused")
    @SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE")
    final SomeMockClass mock = new SomeMockClass();
    ...
    }
}
Run Code Online (Sandbox Code Playgroud)

@SuppressFBWarnings这里不起作用。

这里的解决方案是@SuppressFBWarnings向上移动到方法级别:

@Test
@SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE")
public void testSomething() {

    @SuppressWarnings("unused")
    final SomeMockClass mock = new SomeMockClass();
    ...
    }
}
Run Code Online (Sandbox Code Playgroud)

我喜欢使这些注释的范围尽可能小,这样它们就不会抑制真正的问题。这里似乎有必要对整个方法进行注释。


Gar*_*eld 6

更多谷歌搜索+试验,我终于找到了一种方法来做到这一点.

Section 6http://findbugs.sourceforge.net/manual/filter.html下查看.

您需要创建自己的XML文件,其中包含所有自定义的supressions.然后,您需要让build.xml文件了解此文件findbugs.exclude.filter

 <Match>
   <Class name="com.foobar.MyClass" />
   <Method name="someMethod" />
   <Bug pattern="DLS_DEAD_LOCAL_STORE" />
 </Match>
Run Code Online (Sandbox Code Playgroud)

@SuppressWarnings一旦在XML中存在标记,就不需要在方法中添加标记.

希望这有助于某人!