【问题标题】:DLS_DEAD_LOCAL_STORE SuppressWarnings FindBugs false positiveDLS_DEAD_LOCAL_STORE SuppressWarnings FindBugs 误报
【发布时间】:2013-07-22 22:34:15
【问题描述】:

我正在尝试消除 DLS_DEAD_LOCAL_STORE 的误报

这是我迄今为止尝试过的:

@SuppressWarnings("DLS_DEAD_LOCAL_STORE")

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

(基于SuppressWarnings not working on 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。

【问题讨论】:

    标签: java findbugs spring-annotations suppress-warnings


    【解决方案1】:

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

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

    您需要创建自己的 XML 文件,其中包含所有自定义抑制。 然后你需要通过findbugs.exclude.filter让 build.xml 文件知道这个文件

     <Match>
       <Class name="com.foobar.MyClass" />
       <Method name="someMethod" />
       <Bug pattern="DLS_DEAD_LOCAL_STORE" />
     </Match>
    

    一旦 XML 中有 @SuppressWarnings 标签,则无需在方法中添加标签。

    希望这对某人有所帮助!

    【讨论】:

    • 如果您正在寻找修复 Android 构建的解决方案,请将以下内容添加到 build.gradle:findbugs { excludeFilter = file("findBugsFilter.xml") }
    【解决方案2】:

    这段代码我也遇到了同样的问题:

    @Test
    public void testSomething() {
    
        @SuppressWarnings("unused")
        @SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE")
        final SomeMockClass mock = new SomeMockClass();
        ...
        }
    }
    

    @SuppressFBWarnings 在这里不起作用。

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

    @Test
    @SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE")
    public void testSomething() {
    
        @SuppressWarnings("unused")
        final SomeMockClass mock = new SomeMockClass();
        ...
        }
    }
    

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

    【讨论】:

    • 实际问题似乎是 FindBugs 不允许在使用 Sun/Oracle 的 javac 编译器时为 final 局部变量(如您的示例)抑制 DLS_DEAD_LOCAL_STORE,@ 987654321@.
    【解决方案3】:

    As explained in FindBugs documentation,显然 Sun/Oracle 的 javac 编译器经常为 final 局部变量生成死存储。这些 DLS_DEAD_LOCAL_STORE 警告不容易被抑制。

    不知道为什么 XML 过滤器确实有效(如已接受的答案)。

    【讨论】:

      猜你喜欢
      • 2012-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-30
      • 1970-01-01
      • 2014-11-11
      • 1970-01-01
      相关资源
      最近更新 更多