IllegalToken

Since Checkstyle 3.2

Description

Checks for illegal tokens. By default, labels are prohibited.

Rationale: Certain language features can harm readability, lead to confusion or are not obvious to novice developers. Other features may be discouraged in certain frameworks, such as not having native methods in Enterprise JavaBeans components.

Properties

name description type default value since
tokens tokens to check set of any supported tokens LABELED_STAT . 3.2

Examples

To configure the check:

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

Example:

class Example1 {
  void InvalidExample() {
    outer: // violation, 'Using 'outer:' is not allowed'
    for (int i = 0; i < 5; i++) {
      if (i == 1) {
        break outer;
      }
    }
  }
}
        

To configure the check to report violation on token LITERAL_NATIVE:

<module name="Checker">
  <module name="TreeWalker">
    <module name="IllegalToken">
      <property name="tokens" value="LITERAL_NATIVE"/>
    </module>
  </module>
</module>
        

Example:

class Example2 {
  native void InvalidExample(); // violation, 'Using 'native' is not allowed'
}
        

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.

Package

com.puppycrawl.tools.checkstyle.checks.coding

Parent Module

TreeWalker