问题描述
我跑我的Eclipse项目FindBugs的,并得到了潜在的错误警告,我想燮特定原因preSS(这个问题的环境之外)。这里的code:
I ran FindBugs on my Eclipse project and got a potential bug warning that I would like to suppress for a specific reason (outside the context of this question). Here's the code:
public class LogItem {
private String name;
private void setName(final String nm) {
name = nm;
}
}
当您在本类中运行FindBugs的是给你的 NAME =纳米
赋值操作警告,指出:未读领域:com.me .myorg.LogItem.name
。
When you run FindBugs on this class is gives you a warning on the name = nm
assignment operation, stating: Unread field: com.me.myorg.LogItem.name
.
所以我尝试添加此:
private void setName(final String nm) {
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "NP", justification = "Because I can")
name = nm;
}
当我这样做,我得到一个语法(编译)错误在Eclipse中,他说:
When I do this I get a syntax (compile) error in Eclipse, stating:
复制局部变量处;名称不能被解析为一个类型。
于是我尝试添加在球场上本身FindBugs的燮pressWarnings
,但经过重新运行的类FindBugs的不同,FindBugs仍然抱怨同一行code,并出于同样的原因。我甚至尝试添加燮pressWarnings
到的setName
方法,仍然没有什么区别。
So then I tried adding the FindBugs' SuppressWarnings
on the field itself, but after re-running FindBugs on the class, FindBugs is still complaining about the same line of code and for the same reason. I even tried adding the SuppressWarnings
to the setName
method, and still no difference.
如何(的究竟的!)我使用此批注安静FindBugs的?!
How (exactly!) do I use this annotation to quiet FindBugs?!?
推荐答案
放在该领域的注解和修正错误标识。这对我的作品:
Put the annotation on the field and fix the bug identifier. This works for me:
public class LogItem {
@edu.umd.cs.findbugs.annotations.SuppressWarnings("URF_UNREAD_FIELD")
private String name;
这篇关于燮pressWarnings不工作的FindBugs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!