Findbugs

Description

Checks java classes for common coding errors.

The class directory will be recursively scanned for Java class files and jars to scan for errors.

It is possible to refine the set of classes and archives that are being scanned. This can be done with the includes, includesfile, excludes, and excludesfile attributes. With the includes or includesfile attribute, you specify the files you want to have included. The exclude or excludesfile attribute is used to specify the files you want to have excluded. In both cases, the list of files can be specified by either the filename, relative to the directory(s) specified in the classdir attribute or nested <classdir> element(s), or by using wildcard patterns. See the section on directory-based tasks, for information on how the inclusion/exclusion of files works, and how to write wildcard patterns.

Parameters

Attribute Description Required
classdir Location of the java classes. (See the note below.) Yes, unless nested <classdir> elements are present.
includes Comma- or space-separated list of files (may be specified using wildcard patterns) that must be included; all .java files are included when omitted. No
includesfile The name of a file that contains a list of files to include (may be specified using wildcard patterns). No
excludes Comma- or space-separated list of files (may be specified using wildcard patterns) that must be excluded; no files (except default excludes) are excluded when omitted. No
excludesfile The name of a file that contains a list of files to exclude (may be specified using wildcard patterns). No
classpath The classpath to use. No
classpathref The classpath to use, given as a to a path defined elsewhere. No
sorted See output sorted by classname; defaults to false No
listfiles list the classes and archives findbugs will scan No
nowarn Indicates whether the -nowarn switch should be passed to the compiler; defaults to off. No
failonerror Indicates whether the build will continue even if there are errors detected; defaults to true. No

Parameters specified as nested elements

This task forms an implicit and supports all attributes of <fileset> (dir becomes classdir) as well as the nested <include>, <exclude> and <patternset> elements.

classdir, classpath,

<findbugs>'s classdir, and classpath attributes are path-like structures and can also be set via nested <classdir>, and <classpath> elements, respectively.

error suppression

You can specify error suppression with nested <suppress> elements. This element has three attributes to control the level of error suppression as defined in the following table

Attribute Description Required
error The 2 or 3 letter error code Yes
class The name of the class (wildcards are allowed) No - if not specified all classes match
method The name of the class method (wildcards are allowed) No - if not specified all methods match

Examples

  <findbugs classdir="${build.dir}"
         classpath="xyz.jar"
  />

scan all .class and .jar files under the ${build.dir} directory.

  <findbugs classdir="${build.dir}"
          <include name="**.jar" /> 
  </findbugs>

scan all .jar files under the ${build.dir} directory

  <findbugs classdir="${buil.dir}"
          <suppress error="sic" />
          <suppress error="se" class="**.legacy.**" />
          <suppress error="ei" class="**.Transparent" method="getClients" />
  />

scan all .class files under the ${build.dir} directory ignoring all sic errors, se errors in any class that has legacy as part of it name, and any ei errors in the class named Transparent on the method named getClients.

  <findbugs classdir="${build.dir}"
         includes="mypackage/p1/**,mypackage/p2/**"
         excludes="mypackage/p1/testpackage/**"
         classpath="xyz.jar"
  />

scan .class files under the ${build.dir} directory. Only files under mypackage/p1 and mypackage/p2 are used. All files in and below the mypackage/p1/testpackage directory are excluded from the scan.

is the same as the previous example, with the addition of a second classdir path, defined by the property build.dir2 as a nested <classdir>

  <findbugs 
    <src path="${build.dir}"/>
    <src path="${build.dir2}"/>
    <include name="mypackage/p1/**"/>
    <include name="mypackage/p2/**"/>
    <exclude name="mypackage/p1/testpackage/**"/>
  </findbugs>

Note: For effiency - scanning classes contained in a jar is always faster than scanning a class directory structure due to the amount of I/O involved.


Copyright © 2000-2003 Apache Software Foundation. All rights Reserved.