Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Suppressing FindBugs Warnings

DZone's Guide to

Suppressing FindBugs Warnings

· Java Zone ·
Free Resource

Get the Edge with a Professional Java IDE. 30-day free trial.

A few days ago I spoke with my friend, Tomek, about suppressing FindBugs warnings. Here is brief summary of our conversation, which may be interesting for you.

There is one simple method for suppressing the  FindBugs warnings - usage of  edu.umd.cs.findbugs.annotations.SuppressWarnings annotation. Just add it in the place where  FindBugs reported problem, and use the appropriate bug code.

You should start by adding com.google.code.findbugs:annotations:2.0.0 jar to the project dependencies. Then open the bug reported by  FindBugs, and find its code, like in this example:


Finally add something like this to the method holding the code marked by  FindBugs:


That's all, clear the  FindBugs markers, and run it again, the problem will not be reported in this place again.

Nice! Isn't it? - No, it isn't :( - Why you may ask? - Because there is another annotation in java.lang package with exactly the same name (!), used for suppressing different kind of warnings. Shouldn't it be used instead? - Well ...

Another question is if we want to add another jar to the project dependencies just for suppressing  FindBugs warnings - thank God the  FindBugs authors marked this annotation with retention policy 'CLASS', which means the jar will not be required when running the project (ex. in web application container).

Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}