SuppressWarningsHolder

Since Checkstyle 5.7

Description

Maintains a set of check suppressions from @SuppressWarnings annotations. It allows to prevent Checkstyle from reporting violations from parts of code that were annotated with @SuppressWarnings and using name of the check to be excluded. It is possible to suppress all the checkstyle warnings with the argument "all". You can also use a checkstyle: prefix to prevent compiler from processing these annotations. You can also define aliases for check names that need to be suppressed.

Properties

name description type default value since
aliasList Specify aliases for check names that can be used in code within SuppressWarnings. String[] in a format of comma separated attribute=value entries. The attribute is the fully qualified name of the Check and value is its alias. null 5.7

Examples

To use default module configuration:

<module name="Checker">
  <module name="TreeWalker">
  <module name="MemberName"/>
  <module name="ConstantName"/>
  <module name="ParameterNumber">
    <property name="id" value="ParamNumberId"/>
  </module>
  <module name="NoWhitespaceAfter"/>

  <module name="SuppressWarningsHolder"/>
  </module>
  <module name="SuppressWarningsFilter"/>
</module>
        

Example:

class Test {

   private int K; // violation
   @SuppressWarnings({"membername"})
   private int J; // violation suppressed

   private static final int i = 0; // violation
   @SuppressWarnings("checkstyle:constantname")
   private static final int m = 0; // violation suppressed

   public void needsLotsOfParameters (int a, // violation
      int b, int c, int d, int e, int f, int g, int h) {
      // ...
   }

   @SuppressWarnings("ParamNumberId")
   public void needsLotsOfParameters1 (int a, // violation suppressed
      int b, int c, int d, int e, int f, int g, int h) {
      // ...
   }

   private int [] ARR; // 2 violations
   @SuppressWarnings("all")
   private int [] ARRAY; // violations suppressed
}
        

The general rule is that the argument of the @SuppressWarnings will be matched against class name of the check in any letter case. Adding check suffix is also accepted.

If aliasList property was provided you can use your own names e.g. below code will work if there was provided a ParameterNumberCheck=paramnum in the aliasList:

<module name="Checker">
  <module name="TreeWalker">
  <module name="ParameterNumber"/>

  <module name="SuppressWarningsHolder">
    <property name="aliasList" value=
      "com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck=paramnum"/>
  </module>
  </module>
  <module name="SuppressWarningsFilter"/>
</module>
        

Example:

class Test {

   public void needsLotsOfParameters (int a, // violation
      int b, int c, int d, int e, int f, int g, int h) {
      // ...
   }

   @SuppressWarnings("paramnum")
   public void needsLotsOfParameters1 (int a, // violation suppressed
      int b, int c, int d, int e, int f, int g, int h) {
      // ...
   }

}
        

Example of Usage

Package

com.puppycrawl.tools.checkstyle.checks

Parent Module

TreeWalker