【问题标题】:Findbugs Java Ignore Fields or LinesFindbugs Java 忽略字段或行
【发布时间】:2014-10-16 06:34:22
【问题描述】:

是否可以为特定字段或行制作 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;

【问题讨论】:

  • 嗯,为什么你要这样覆盖那个方法?
  • 这只是一个简化的例子,大多数普通屏幕都无法在屏幕上获取此方法的代码 xD 这个没有意义,但问题是一样的。

标签: java annotations findbugs


【解决方案1】:

字段可以,但单行代码不行。根据FindBugs 3.0 documentation,可以应用@SuppressFBWarnings注解

[目标] 类型、字段、方法、参数、构造函数、包

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

如您所见,LOCAL_VARIABLEANNOTATION_TYPE 不在列表中。虽然注解上没有 @Target 元素,但 FindBugs 在这两种情况下都会忽略它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-18
    • 1970-01-01
    • 2010-09-07
    • 2016-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多