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;
}
}
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
.
So I tried adding this:
private void setName(final String nm) {
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "NP", justification = "Because I can")
name = nm;
}
When I do this I get a syntax (compile) error in Eclipse, stating:
Duplicate local variable nm; name cannot be resolved to a type.
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.
How (exactly!) do I use this annotation to quiet FindBugs?!?