I ran FindBugs on my Eclipse project and received a potential error warning that I would like to suppress for a specific reason (outside the context of this question). Here is the code:
public class LogItem { private String name; private void setName(final String nm) { name = nm; } }
When you run FindBugs in this class, you will receive a warning that the name = nm task has completed, indicating: Unread field: com.me.myorg.LogItem.name .
So I tried to add 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 (compilation) error in Eclipse by indicating:
Duplicate of local variable nm; name cannot be resolved to type.
So, I tried to add FindBugs' SuppressWarnings in the field itself, but after running FindBugs again in the FindBugs class, it still complains about the same line of code and for the same reason. I even tried adding the SuppressWarnings method to the setName method, and there is still no difference.
How (for sure!) Do I use this annotation for silent FindBugs?!?
source share