You should definitely use FindBugs. In my experience, the false-positive rate is very low, and even the least-critical warnings it reports are worth addressing to some extent.
As for Checkstyle vs. PMD, I would not use Checkstyle since it is pretty much only concerned with style. In my experience, Checkstyle will report on a ton of things that are completely irrelevant. PMD on the other hand is also able to point out questionable coding practices and its output is generally more relevant and useful.
Check out the use of the supressionCommentFilter at http://checkstyle.sourceforge.net/config_filters.html#SuppressionCommentFilter. You'll need to add the module to your checkstyle.xml
<module name="SuppressionCommentFilter"/>
and it's configurable. Thus you can add comments to your code to turn off checkstyle (at various levels) and then back on again through the use of comments in your code. E.g.
//CHECKSTYLE:OFF
public void someMethod(String arg1, String arg2, String arg3, String arg4) {
//CHECKSTYLE:ON
Or even better, use this more tweaked version:
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="CHECKSTYLE.OFF\: ([\w\|]+)"/>
<property name="onCommentFormat" value="CHECKSTYLE.ON\: ([\w\|]+)"/>
<property name="checkFormat" value="$1"/>
</module>
which allows you to turn off specific checks for specific lines of code:
//CHECKSTYLE.OFF: IllegalCatch - Much more readable than catching 7 exceptions
catch (Exception e)
//CHECKSTYLE.ON: IllegalCatch
*Note: you'll also have to add the FileContentsHolder
:
<module name="FileContentsHolder"/>
See also
<module name="SuppressionFilter">
<property name="file" value="docs/suppressions.xml"/>
</module>
under the SuppressionFilter
section on that same page, which allows you to turn off individual checks for pattern matched resources.
So, if you have in your checkstyle.xml:
<module name="ParameterNumber">
<property name="id" value="maxParameterNumber"/>
<property name="max" value="3"/>
<property name="tokens" value="METHOD_DEF"/>
</module>
You can turn it off in your suppression xml file with:
<suppress id="maxParameterNumber" files="YourCode.java"/>
Another method, now available in Checkstyle 5.7 is to suppress violations via the @SuppressWarnings
java annotation. To do this, you will need to add two new modules (SuppressWarningsFilter
and SuppressWarningsHolder
) in your configuration file:
<module name="Checker">
...
<module name="SuppressWarningsFilter" />
<module name="TreeWalker">
...
<module name="SuppressWarningsHolder" />
</module>
</module>
Then, within your code you can do the following:
@SuppressWarnings("checkstyle:methodlength")
public void someLongMethod() throws Exception {
or, for multiple suppressions:
@SuppressWarnings({"checkstyle:executablestatementcount", "checkstyle:methodlength"})
public void someLongMethod() throws Exception {
NB: The "checkstyle:
" prefix is optional (but recommended). According to the docs the parameter name have to be in all lowercase, but practice indicates any case works.
Best Answer
Browsing the documentation it looks to me that your metadata element is pointless. Perhaps it even provokes the checkstyle parser to ignore the JavadocPackage configuration.
Also, when the allowLegacy property is set (it's false by default), you specify that you want to use a package.html file. It is not allowed to have both a package.html and package-info.java files.
Edit:
I have just tested the above. It seems that the error is misleading. What it actually means is that a package.html file is missing :) Just add it and the warning will disappear.