InappropriateJavadocBlockTagsOnField

Since Checkstyle 14.1.0

Description

Checks that Javadoc block tags for field declarations do not contain tags that are semantically invalid for fields. Specifically, @author, @version, @param, @return, @throws/@exception, @uses, and @provides tags are meaningless on field declarations.

Field declarations do not have parameters, return types, or throw declarations, and module/type-level tags like @author, @version, @uses, and @provides are inappropriate on field declarations. Therefore, such Javadoc block tags are considered inappropriate and should be removed.

Properties

name description type default value since
violateExecutionOnNonTightHtml Control when to print violations if the Javadoc being examined by this check violates the tight html rules defined at Tight-HTML Rules. boolean false 14.1.0

Examples

To configure the check:


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

Example:


class Example1 {
  /**
   * Valid Javadoc on field.
   *
   * @since 1.0
   * @see Object
   */
  private String field1;

  /**
   * Inappropriate tags on class field.
   *
   * @param BAD Invalid tag for field.
   * @return Invalid tag for field.
   * @throws Exception Invalid tag for field.
   */
  private String field2;
  // 3 violations above:
  // 'Invalid '@param' tag for 'field2'.'
  // 'Invalid '@return' tag for 'field2'.'
  // 'Invalid '@throws' tag for 'field2'.'

  void method() {
    /**
     * Local variables are not fields, so no violations are reported.
     *
     * @return local
     */
    int localVariable = 0; // ok, local variables are not fields
  }

  interface MyInterface {
    /**
     * Inappropriate tags on interface field.
     *
     * @param BAD Invalid tag for field.
     * @return Invalid tag for field.
     */
    int INT_FIELD = 0;
    // 2 violations above:
    // 'Invalid '@param' tag for 'INT_FIELD'.'
    // 'Invalid '@return' tag for 'INT_FIELD'.'
  }
}

Example of Usage

Violation Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Fully Qualified Name

com.puppycrawl.tools.checkstyle.checks.javadoc.InappropriateJavadocBlockTagsOnFieldCheck

Use this fully qualified class name in configuration when an exact class reference is required.

Parent Module

TreeWalker