blob: c44d889f6aa61ae9a81466d6d695c120bad8b1be [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<document xmlns="http://maven.apache.org/XDOC/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd">
<head>
<title>Coding</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"/>
<script type="text/javascript" src="js/anchors.js"/>
<script type="text/javascript" src="js/google-analytics.js"/>
<link rel="icon" href="images/favicon.png" type="image/x-icon" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/ico" />
</head>
<body>
<section name="Content">
<macro name="toc">
<param name="fromDepth" value="1"/>
<param name="toDepth" value="1"/>
</macro>
</section>
<section name="ArrayTrailingComma">
<subsection name="Description">
<p>Since Checkstyle 3.2</p>
<p>
Checks that array initialization contains a trailing comma.
</p>
<source>
int[] a = new int[]
{
1,
2,
3,
};
</source>
<p>
The check demands a comma at the end if neither left nor right curly braces
are on the same line as the last element of the array.
</p>
<source>
return new int[] { 0 };
return new int[] { 0
};
return new int[] {
0 };
</source>
<p>
Rationale: Putting this comma in makes it easier to change the order
of the elements or add new elements on the end. Main benefit of a trailing
comma is that when you add new entry to an array, no surrounding lines are changed.
</p>
<source>
{
100000000000000000000,
200000000000000000000, // OK
}
{
100000000000000000000,
200000000000000000000,
300000000000000000000, // Just this line added, no other changes
}
</source>
<p>
If closing brace is on the same line as training comma, this benefit is gone
(as the Check does not demand a certain location of curly braces the following
two cases will not produce a violation):
</p>
<source>
{100000000000000000000,
200000000000000000000,} // Trailing comma not needed, line needs to be modified anyway
{100000000000000000000,
200000000000000000000, // Modified line
300000000000000000000,} // Added line
</source>
<p>
If opening brace is on the same line as training comma there's also (more arguable) problem:
</p>
<source>
{100000000000000000000, // Line cannot be just duplicated to slightly modify entry
}
{100000000000000000000,
100000000000000000001, // More work needed to duplicate
}
</source>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;ArrayTrailingComma&quot;/&gt;
</source>
<p>
Which results in the following violations:
</p>
<source>
int[] numbers = {1, 2, 3}; //no violation
boolean[] bools = {
true,
true,
false
}; //violation
String[][] text = {{},{},}; //no violation
double[][] decimals = {
{0.5, 2.3, 1.1,}, //no violation
{1.7, 1.9, 0.6},
{0.8, 7.4, 6.5}
}; // violation as previous line misses a comma
char[] chars = {'a', 'b', 'c'
}; / /no violation
String[] letters = {
"a", "b", "c"}; // no violation
int[] a1 = new int[]{
1,
2
,
}; // no violation
int[] a2 = new int[]{
1,
2
,}; // no violation
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+ArrayTrailingComma">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22array.trailing.comma%22">
array.trailing.comma</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="AvoidInlineConditionals">
<subsection name="Description">
<p>Since Checkstyle 3.1</p>
<p>
Detects inline conditionals. Here is one example of an inline conditional:
</p>
<source>
String a = getParameter("a");
String b = (a==null || a.length&lt;1) ? null : a.substring(1);
</source>
<p>
Rationale: Some developers find inline conditionals hard to read, so
their employer's coding standards forbid them.
</p>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;AvoidInlineConditionals&quot;/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+AvoidInlineConditionals">
Sun Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+AvoidInlineConditionals">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22inline.conditional.avoid%22">
inline.conditional.avoid</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="CovariantEquals">
<subsection name="Description">
<p>Since Checkstyle 3.2</p>
<p>
Checks that classes which define a covariant <code>equals()</code> method
also override method <code>equals(Object)</code>.<br/>
Covariant <code>equals()</code> - method that is similar to <code>equals(Object)</code>,
but with a covariant parameter type (any subtype of Object).<br/>
<strong>Notice</strong>: the enums are also checked, even
though they cannot override <code>equals(Object)</code>. The reason is
to point out that implementing <code>equals()</code> in enums is considered an
awful practice: it may cause having two different enum values that are equal using
covariant enum method, and not equal when compared normally.
</p>
<p>
Inspired by <a href="https://cs.nyu.edu/~lharris/papers/findbugsPaper.pdf">
Finding Bugs is Easy, chapter '2.3.1 Bad Covariant Definition of Equals (Eq)'</a>:
</p>
<p>
Java classes may override the <code>equals(Object)</code> method to define
a predicate for object equality. This method is used by many of the Java runtime
library classes; for example, to implement generic containers.
</p>
<p>
Programmers sometimes mistakenly use the type of their class <code>Foo</code>
as the type of the parameter to <code>equals()</code>:
</p>
<source>
public boolean equals(Foo obj) {...}
</source>
<p>
This covariant version of <code>equals()</code> does not override the version in the
<code>Object</code> class, and it may lead to unexpected behavior at runtime,
especially if the class is used with one of the standard collection classes
which expect that the standard <code>equals(Object)</code> method is overridden.
</p>
<p>
This kind of bug is not obvious because it looks correct, and in circumstances where
the class is accessed through the references of the class type (rather than a supertype),
it will work correctly. However, the first time it is used in a container,
the behavior might be mysterious. For these reasons, this type of bug can elude
testing and code inspections.
</p>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;CovariantEquals&quot;/&gt;
</source>
<p>
For example:
<source>
class Test {
public boolean equals(Test i) { // violation
return false;
}
}
</source>
</p>
<p>
The same class without violations:
<source>
class Test {
public boolean equals(Test i) { // no violation
return false;
}
public boolean equals(Object i) {
return false;
}
}
</source>
</p>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+CovariantEquals">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22covariant.equals%22">
covariant.equals</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="DeclarationOrder">
<subsection name="Description">
<p>Since Checkstyle 3.2</p>
<p>
According to <a
href="http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-141855.html#1852">
Code Conventions for the Java Programming Language</a> , the parts
of a class or interface declaration should appear in the following
order:
</p>
<ol>
<li>
Class (static) variables. First the public class variables, then
protected, then package level (no access modifier), and then
private.
</li>
<li>
Instance variables. First the public class variables, then
protected, then package level (no access modifier), and then
private.
</li>
<li> Constructors </li>
<li> Methods </li>
</ol>
<p>
Purpose of <b>ignore*</b> option is to ignore related violations, however it still impacts on other class members.
</p>
<p>
ATTENTION: the check skips class fields which have
<a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.3.3">forward references</a>
from validation due to the fact that we have Checkstyle's limitations to clearly
detect user intention of fields location and grouping. For example,
<source>
public class A {
private double x = 1.0;
private double y = 2.0;
public double slope = x / y; // will be skipped from validation due to forward reference
}
</source>
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>ignoreConstructors</td>
<td>whether to ignore constructors</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><code>false</code></td>
<td>5.2</td>
</tr>
<tr>
<td>ignoreModifiers</td>
<td>whether to ignore modifiers</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><code>false</code></td>
<td>5.2</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;DeclarationOrder&quot;/&gt;
</source>
<p>
For example:
<source>
class K {
int a;
void m(){}
K(){} &lt;-- "Constructor definition in wrong order"
int b; &lt;-- "Instance variable definition in wrong order"
}
</source>
</p>
<p>
With <b>ignoreConstructors</b> option:
<source>
class K {
int a;
void m(){}
K(){}
int b; &lt;-- "Instance variable definition in wrong order"
}
</source>
</p>
<p>
With <b>ignoreConstructors</b> option and without a method definition in a source class:
<source>
class K {
int a;
K(){}
int b; &lt;-- "Instance variable definition in wrong order"
}
</source>
</p>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+DeclarationOrder">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22declaration.order.access%22">
declaration.order.access</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22declaration.order.constructor%22">
declaration.order.constructor</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22declaration.order.instance%22">
declaration.order.instance</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22declaration.order.static%22">
declaration.order.static</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="DefaultComesLast">
<subsection name="Description">
<p>Since Checkstyle 3.4</p>
<p>
Check that the <code>default</code> is after all the
<code>case</code>s in a <code>switch</code> statement.
</p>
<p>
Rationale: Java allows <code>default</code> anywhere
within the <code>switch</code> statement. But it is
more readable if it comes after the last <code>case</code>.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>skipIfLastAndSharedWithCase</td>
<td>whether to allow <code>default</code> along with case if they are not last</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td>false</td>
<td>7.7</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;DefaultComesLast&quot;/&gt;
</source>
<p>
To configure the check for skipIfLastAndSharedWithCase:
</p>
<source>
&lt;module name=&quot;DefaultComesLast&quot;&gt;
&lt;property name=&quot;skipIfLastAndSharedWithCase&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
</source>
<p>
Example when skipIfLastAndSharedWithCase is set to true.
</p>
<source>
switch (i) {
case 1:
break;
case 2:
default: // No violation with the new option is expected
break;
case 3:
break;
}
switch (i) {
case 1:
break;
default: // violation with the new option is expected
case 2:
break;
}
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+DefaultComesLast">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22default.comes.last%22">
default.comes.last</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22default.comes.last.in.casegroup%22">
default.comes.last.in.casegroup</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="EmptyStatement">
<subsection name="Description">
<p>Since Checkstyle 3.1</p>
<p>
Detects empty statements (standalone ";" semicolon).
</p>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;EmptyStatement&quot;/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+EmptyStatement">
Sun Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+EmptyStatement">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22empty.statement%22">
empty.statement</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="EqualsAvoidNull">
<subsection name="Description">
<p>Since Checkstyle 5.0</p>
<p>
Checks that any combination of String literals
is on the left side of an equals() comparison.
Also checks for String literals assigned to some field
(such as <code>someString.equals(anotherString = "text")</code>).
</p>
<p>
Rationale: Calling the <code>equals()</code>
method on String literals will avoid a potential
NullPointerException. Also, it is pretty common to see null
checks right before equals comparisons, which is not necessary
in the example below.
</p>
<p>
For example, this code:
</p>
<source>
String nullString = null;
nullString.equals(&quot;My_Sweet_String&quot;);
</source>
<p>should be refactored to:</p>
<source>
String nullString = null;
&quot;My_Sweet_String&quot;.equals(nullString);
</source>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>ignoreEqualsIgnoreCase</td>
<td>whether to ignore <code>String.equalsIgnoreCase()</code> invocations</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td>false</td>
<td>5.4</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;EqualsAvoidNull&quot;/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+EqualsAvoidNull">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22equals.avoid.null%22">
equals.avoid.null</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22equalsIgnoreCase.avoid.null%22">
equalsIgnoreCase.avoid.null</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="EqualsHashCode">
<subsection name="Description">
<p>Since Checkstyle 3.0</p>
<p>
Checks that classes that either override <code>equals()</code>
or <code>hashCode()</code> also overrides the other.
This checks only verifies that the method declarations match
<code>Object.equals(Object)}</code> and <code>Object.hashCode()</code> exactly to be
considered an override. This check does not verify invalid method names, parameters
other than <code>Object</code>, or anything else.
</p>
<p>
Rationale: The contract of <code>equals()</code> and
<code>hashCode()</code> requires that equal objects
have the same hashCode. Therefore, whenever you override <code>equals()</code> you must override <code>
hashCode()</code> to ensure that your class can be used in
hash-based collections.
</p>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;EqualsHashCode&quot;/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+EqualsHashCode">
Sun Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+EqualsHashCode">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22equals.noEquals%22">
equals.noEquals</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22equals.noHashCode%22">
equals.noHashCode</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="ExplicitInitialization">
<subsection name="Description">
<p>Since Checkstyle 3.2</p>
<p>
Checks if any class or object member is explicitly initialized to
default for its type value (<code>null</code> for
object references, zero for numeric types and <code>char</code> and <code>false</code> for
<code>boolean</code>.
</p>
<p>
Rationale: Each instance variable gets initialized twice, to the
same value. Java initializes each instance variable to its default
value (0 or null) before performing any initialization specified in
the code. So in this case, x gets initialized to 0 twice, and bar
gets initialized to null twice. So there is a minor inefficiency.
This style of coding is a holdover from C/C++ style coding, and it
shows that the developer isn't really confident that Java
initializes instance variables to default values.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>onlyObjectReferences</td>
<td>whether only explicit initializations made to
null for objects should be checked</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><code>false</code></td>
<td>7.8</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;ExplicitInitialization&quot;/&gt;
</source>
<p>
To configure the check so that it only checks
for objects that explicitly initialize to null:
</p>
<source>
&lt;module name=&quot;ExplicitInitialization&quot;&gt;
&lt;property name=&quot;onlyObjectReferences&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
</source>
<p>Example:</p>
<p>
<source>
public class Test {
private int a = 0;
private int b = 1;
private int c = 2;
private boolean a = true;
private boolean b = false;
private boolean c = true;
private boolean d = false;
private boolean e = false;
private A a = new A();
private A b = null; // violation
private C c = null; // violation
private D d = new D();
int ar1[] = null; // violation
int ar2[] = new int[];
int ar3[];
private Bar&lt;String&gt; bar = null; // violation
private Bar&lt;String&gt;[] barArray = null; // violation
public static void main( String [] args ) {
}
}
</source>
</p>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+ExplicitInitialization">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22explicit.init%22">
explicit.init</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="FallThrough">
<subsection name="Description">
<p>Since Checkstyle 3.4</p>
<p>
Checks for fall-through in <code>switch</code>
statements. Finds locations where a <code>case</code>
<b>contains</b> Java code but lacks a <code>break</code>, <code>return</code>,
<code>throw</code> or <code>continue</code>
statement.
</p>
<p>
The check honors special comments to suppress the warning. By
default the text "fallthru", "fall through", "fallthrough",
"falls through" and "fallsthrough" are recognized (case
sensitive). The comment containing these words must be all on one line, and must
be on the last non-empty line before the
<code>case</code> triggering the warning or on
the same line before the <code>case</code>
(ugly, but possible).
</p>
<source>
switch (i){
case 0:
i++; // fall through
case 1:
i++;
// falls through
case 2:
case 3:
case 4: {
i++;
}
// fallthrough
case 5:
i++;
/* fallthru */case 6:
i++
break;
}
</source>
<p>
Note: The check assumes that there is no unreachable
code in the <code>case</code>.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>checkLastCaseGroup</td>
<td>
Whether the last case group must be checked.
</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><code>false</code></td>
<td>4.0</td>
</tr>
<tr>
<td>reliefPattern</td>
<td>
Regular expression to match the relief comment that suppresses
the warning about a fall through.
</td>
<td><a href="property_types.html#regexp">Regular Expression</a></td>
<td><code>"fallthru|falls? ?through"</code></td>
<td>4.0</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;FallThrough&quot;/&gt;
</source>
<p>
or
</p>
<source>
&lt;module name=&quot;FallThrough&quot;&gt;
&lt;property name=&quot;reliefPattern&quot; value=&quot;continue in next case&quot;/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+FallThrough">
Google Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+FallThrough">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22fall.through%22">
fall.through</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22fall.through.last%22">
fall.through.last</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="FinalLocalVariable">
<subsection name="Description">
<p>Since Checkstyle 3.2</p>
<p>
Checks that local variables that never have their values changed are
declared final. The check can be configured to also check that
unchanged parameters are declared final.
</p>
</subsection>
<subsection name="Notes">
<p>
When configured to check parameters, the check ignores parameters of
interface methods and abstract methods.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr class="header">
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>validateEnhancedForLoopVariable</td>
<td>Controls whether to check <a href = "https://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.14.2">enhanced for-loop</a> variable.</td>
<td>
<a
href="property_types.html#boolean">Boolean</a>
</td>
<td>
<code>
false
</code>
</td>
<td>6.5</td>
</tr>
<tr>
<td>tokens</td>
<td>tokens to check</td>
<td>
subset of tokens <a
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">VARIABLE_DEF</a>,
<a
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PARAMETER_DEF">PARAMETER_DEF</a>.
</td>
<td>
<a
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">VARIABLE_DEF</a>.
</td>
<td>3.2</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;FinalLocalVariable&quot;/&gt;
</source>
<p>
To configure the check so that it checks local variables and
parameters:
</p>
<source>
&lt;module name=&quot;FinalLocalVariable&quot;&gt;
&lt;property name=&quot;tokens&quot; value=&quot;VARIABLE_DEF,PARAMETER_DEF&quot;/&gt;
&lt;/module&gt;
</source>
<p>
By default, this Check skip final validation on
<a href = "https://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.14.2">
Enhanced For-Loop</a>.
</p>
<p>
Option 'validateEnhancedForLoopVariable' could be used to make Check to validate even variable
from Enhanced For Loop.
</p>
<p>
An example of how to configure the check so that it also validates enhanced For Loop Variable is:
</p>
<source>
&lt;module name="FinalLocalVariable"&gt;
&lt;property name="tokens" value="VARIABLE_DEF"/&gt;
&lt;property name="validateEnhancedForLoopVariable" value="true"/&gt;
&lt;/module&gt;
</source>
<p>Example:</p>
<p>
<source>
for (int number : myNumbers) { // violation
System.out.println(number);
}
</source>
</p>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+FinalLocalVariable">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22final.variable%22">
final.variable</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="HiddenField">
<subsection name="Description">
<p>Since Checkstyle 3.0</p>
<p>
Checks that a local variable or a parameter does not shadow a field
that is defined in the same class.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>ignoreFormat</td>
<td>pattern for names of variables and parameters to ignore</td>
<td><a href="property_types.html#regexp">Regular Expression</a></td>
<td><code>null</code></td>
<td>3.2</td>
</tr>
<tr>
<td>ignoreConstructorParameter</td>
<td>Controls whether to ignore constructor parameters.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><code>false</code></td>
<td>3.2</td>
</tr>
<tr>
<td>ignoreSetter</td>
<td>
Controls whether to ignore the parameter of a property setter
method, where the property setter method for field
&quot;xyz&quot; has name &quot;setXyz&quot;, one parameter named
&quot;xyz&quot; and return type of <code>void</code>
( default behavior) or class in which method is declared (only
if property <code>setterCanReturnItsClass</code> is set
to <code>true</code>).
</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><code>false</code></td>
<td>3.2</td>
</tr>
<tr>
<td>setterCanReturnItsClass</td>
<td>
Used in conjunction with <code>ignoreSetter</code> property it
controls rule that recognizes method as a setter. By default
setter is a method with signature of type
<pre>
void setXyz(${someType} xyz)
</pre>
By setting this property (<code>setterCanReturnItsClass</code>)
to <code>true</code> we expand definition of setter to also
include returning class in which setter is defined. For example
<pre>
class Foo {
int prop;
Foo setProp(int prop) {
this.prop = prop;
return this;
}
}
</pre>
</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><code>false</code></td>
<td>6.3</td>
</tr>
<tr>
<td>ignoreAbstractMethods</td>
<td>Controls whether to ignore parameters of abstract methods.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><code>false</code></td>
<td>4.0</td>
</tr>
<tr>
<td>tokens</td>
<td>tokens to check</td>
<td>
subset of tokens <a
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">VARIABLE_DEF</a>,
<a
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PARAMETER_DEF">PARAMETER_DEF</a>,
LAMBDA.
</td>
<td>
<a
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">VARIABLE_DEF</a>,
<a
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PARAMETER_DEF">PARAMETER_DEF</a>,
LAMBDA.
</td>
<td>3.0</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;HiddenField&quot;/&gt;
</source>
<p>
To configure the check so that it checks local variables but not
parameters:
</p>
<source>
&lt;module name=&quot;HiddenField&quot;&gt;
&lt;property name=&quot;tokens&quot; value=&quot;VARIABLE_DEF&quot;/&gt;
&lt;/module&gt;
</source>
<p>
To configure the check so that it ignores the variables and parameters named
&quot;test&quot;:
</p>
<source>
&lt;module name=&quot;HiddenField&quot;&gt;
&lt;property name=&quot;ignoreFormat&quot; value=&quot;^test$&quot;/&gt;
&lt;/module&gt;
</source>
<source>
class SomeClass
{
private List&lt;String&gt; test;
private void addTest(List&lt;String&gt; test) // no violation
{
this.test.addAll(test);
}
private void foo()
{
final List&lt;String&gt; test = new ArrayList&lt;&gt;(); // no violation
...
}
}
</source>
<p>
To configure the check so that it ignores constructor parameters:
</p>
<source>
&lt;module name=&quot;HiddenField&quot;&gt;
&lt;property name=&quot;ignoreConstructorParameter&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
</source>
<p>
To configure the check so that it ignores the parameter of setter
methods:
</p>
<source>
&lt;module name=&quot;HiddenField&quot;&gt;
&lt;property name=&quot;ignoreSetter&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
</source>
<p>
To configure the check so that it ignores the parameter of setter
methods recognizing setter as returning either <code>void</code> or
a class in which it is declared:
</p>
<source>
&lt;module name=&quot;HiddenField&quot;&gt;
&lt;property name=&quot;ignoreSetter&quot; value=&quot;true&quot;/&gt;
&lt;property name=&quot;setterCanReturnItsClass&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+HiddenField">
Sun Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+HiddenField">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22hidden.field%22">
hidden.field</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="IllegalCatch">
<subsection name="Description">
<p>Since Checkstyle 3.2</p>
<p>
Checks that certain exception types do not appear in a <code>catch</code> statement.
</p>
<p>
Rationale:
Catching java.lang.Exception, java.lang.Error or
java.lang.RuntimeException is almost never acceptable.
Novice developers often simply catch Exception in an
attempt to handle multiple exception classes. This unfortunately
leads to code that inadvertently catches NullPointerException, OutOfMemoryError, etc.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>illegalClassNames</td>
<td>exception class names to reject</td>
<td><a href="property_types.html#stringSet">String Set</a></td>
<td><code>&quot;java.lang.Exception,
java.lang.Throwable, java.lang.RuntimeException&quot;</code></td>
<td>3.2</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;IllegalCatch&quot;/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+IllegalCatch">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22illegal.catch%22">
illegal.catch</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="IllegalInstantiation">
<subsection name="Description">
<p>Since Checkstyle 3.0</p>
<p>
Checks for illegal instantiations where a factory method is
preferred.
</p>
<p>
Rationale: Depending on the project, for some classes it might be
preferable to create instances through factory methods rather than
calling the constructor.
</p>
<p>
A simple example is the <code>java.lang.Boolean</code>
class. For performance reasons, it is preferable to
use the predefined constants <code> TRUE</code> and
<code>FALSE</code>. Constructor invocations should be
replaced by calls to <code>Boolean.valueOf()</code>.
</p>
<p>
Some extremely performance sensitive projects may require the use of
factory methods for other classes as well, to enforce the usage of
number caches or object pools.
</p>
</subsection>
<subsection name="Notes">
<p>
There is a limitation that it is currently not possible to specify
array classes.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>classes</td>
<td>classes that should not be instantiated</td>
<td><a href="property_types.html#stringSet">String Set</a></td>
<td>{}</td>
<td>3.0</td>
</tr>
<tr>
<td>tokens</td>
<td>tokens to check</td>
<td>
subset of tokens
CLASS_DEF.
</td>
<td>
CLASS_DEF.
</td>
<td>3.0</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check to find instantiations of java.lang.Boolean:
</p>
<source>
&lt;module name=&quot;IllegalInstantiation&quot;&gt;
&lt;property name=&quot;classes&quot; value=&quot;java.lang.Boolean&quot;/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+IllegalInstantiation">
Sun Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+IllegalInstantiation">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22instantiation.avoid%22">
instantiation.avoid</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="IllegalThrows">
<subsection name="Description">
<p>Since Checkstyle 4.0</p>
<p>
This check can be used to ensure that types are not declared
to be thrown. Declaring that a method throws java.lang.Error or
java.lang.RuntimeException is almost never acceptable.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>illegalClassNames</td>
<td>throw class names to reject</td>
<td><a href="property_types.html#stringSet">String Set</a></td>
<td>
<code>&quot;java.lang.Throwable,
java.lang.Error, java.lang.RuntimeException&quot;</code>
</td>
<td>4.0</td>
</tr>
<tr>
<td>ignoredMethodNames</td>
<td>names of methods to ignore</td>
<td><a href="property_types.html#stringSet">String Set</a></td>
<td><code>finalize</code></td>
<td>5.4</td>
</tr>
<tr>
<td>ignoreOverriddenMethods</td>
<td>ignore checking overridden methods (marked with Override or java.lang.Override
annotation).</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><code>true</code></td>
<td>6.4</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;IllegalThrows&quot;/&gt;
</source>
<p>
To configure the check rejecting throws NullPointerException from methods:
</p>
<source>
&lt;module name=&quot;IllegalThrows&quot;&gt;
&lt;property name=&quot;illegalClassNames&quot; value=&quot;NullPointerException&quot;/&gt;
&lt;/module&gt;
</source>
<p>
To configure the check ignoring method named &quot;foo()&quot;:
</p>
<source>
&lt;module name=&quot;IllegalThrows&quot;&gt;
&lt;property name=&quot;ignoredMethodNames&quot; value=&quot;foo&quot;/&gt;
&lt;/module&gt;
</source>
<p>
To configure the check to warn on overridden methods:
</p>
<source>
&lt;module name=&quot;IllegalThrows&quot;&gt;
&lt;property name=&quot;ignoreOverriddenMethods&quot; value=&quot;false&quot;/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+IllegalThrows">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22illegal.throw%22">
illegal.throw</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="IllegalToken">
<subsection name="Description">
<p>Since Checkstyle 3.2</p>
<p>
Checks for illegal tokens. By default labels are prohibited.
</p>
<p>
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.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>tokens</td>
<td>tokens to check</td>
<td>
subset of tokens
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html">TokenTypes</a>.
</td>
<td>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LABELED_STAT">LABELED_STAT</a>.
</td>
<td>3.2</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check to find token LITERAL_NATIVE:
</p>
<source>
&lt;module name=&quot;IllegalToken&quot;&gt;
&lt;property name=&quot;tokens&quot; value=&quot;LITERAL_NATIVE&quot;/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+IllegalToken">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22illegal.token%22">
illegal.token</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="IllegalTokenText">
<subsection name="Description">
<p>Since Checkstyle 3.2</p>
<p>
Checks specified tokens text for matching an illegal pattern from
<code>format</code> property. By default no tokens are specified.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>format</td>
<td>illegal pattern</td>
<td><a href="property_types.html#regexp">Regular Expression</a></td>
<td><code>&quot;$^&quot; (empty)</code></td>
<td>3.2</td>
</tr>
<tr>
<td>ignoreCase</td>
<td>Controls whether to ignore case when matching.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><code>false</code></td>
<td>3.2</td>
</tr>
<tr>
<td>message</td>
<td>Message which is used to notify about violations;
if empty then the default message is used.</td>
<td><a href="property_types.html#string">String</a></td>
<td><code>&quot;&quot;</code>(empty)</td>
<td>3.2</td>
</tr>
<tr>
<td>tokens</td>
<td>tokens to check</td>
<td>subset of tokens
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_DOUBLE">NUM_DOUBLE</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_FLOAT">NUM_FLOAT</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_INT">NUM_INT</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_LONG">NUM_LONG</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#IDENT">IDENT</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#COMMENT_CONTENT">COMMENT_CONTENT</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STRING_LITERAL">STRING_LITERAL</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CHAR_LITERAL">CHAR_LITERAL</a>.
</td>
<td>empty</td>
<td>3.2</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check to forbid String literals containing <code>&quot;a href&quot;</code>:
</p>
<source>
&lt;module name=&quot;IllegalTokenText&quot;&gt;
&lt;property name=&quot;tokens&quot; value=&quot;STRING_LITERAL&quot;/&gt;
&lt;property name=&quot;format&quot; value=&quot;a href&quot;/&gt;
&lt;/module&gt;
</source>
<p>
To configure the check to forbid leading zeros in an integer
literal, other than zero and a hex literal:
</p>
<source>
&lt;module name=&quot;IllegalTokenText&quot;&gt;
&lt;property name=&quot;tokens&quot; value=&quot;NUM_INT,NUM_LONG&quot;/&gt;
&lt;property name=&quot;format&quot; value=&quot;^0[^lx]&quot;/&gt;
&lt;property name=&quot;ignoreCase&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+IllegalTokenText">
Google Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+IllegalTokenText">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22illegal.token.text%22">
illegal.token.text</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="IllegalType">
<subsection name="Description">
<p>Since Checkstyle 3.2</p>
<p>
Checks that particular classes are never used as types in variable
declarations, one-dimensional and multi-dimensional arrays, return values or parameters.
</p>
<p>
Rationale: Helps reduce coupling on concrete classes.
</p>
<p>
For additional restriction of type usage see also:
<a href="#IllegalInstantiation">IllegalInstantiation</a>, <a href="config_imports.html#IllegalImport">IllegalImport</a>
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>validateAbstractClassNames</td>
<td>Whether to validate abstract class names</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td>false</td>
<td>6.10</td>
</tr>
<tr>
<td>illegalClassNames</td>
<td>Classes that should not be used as types in variable
declarations, return values or parameters</td>
<td><a href="property_types.html#stringSet">String Set</a></td>
<td>&quot;java.util.HashSet, java.util.HashMap, java.util.LinkedHashMap,
java.util.LinkedHashSet, java.util.TreeSet,
java.util.TreeMap&quot;</td>
<td>3.2</td>
</tr>
<tr>
<td>legalAbstractClassNames</td>
<td>Abstract classes that may be used as types. </td>
<td><a href="property_types.html#stringSet">String Set</a></td>
<td/>
<td>4.2</td>
</tr>
<tr>
<td>ignoredMethodNames</td>
<td>Methods that should not be checked.</td>
<td><a href="property_types.html#stringSet">String Set</a></td>
<td>&quot;getInitialContext, getEnvironment&quot; </td>
<td>3.2</td>
</tr>
<tr>
<td>format</td>
<td>Pattern for illegal class names.</td>
<td><a href="property_types.html#regexp">Regular Expression</a></td>
<td><code>"^(.*[.])?Abstract.*$"</code></td>
<td>3.2</td>
</tr>
<tr>
<td>memberModifiers</td>
<td>Check methods and fields with only corresponding modifiers.</td>
<td><a href="property_types.html#stringSet">List of tokens</a></td>
<td><code>null</code></td>
<td>6.3</td>
</tr>
<tr>
<td>tokens</td>
<td>tokens to check</td>
<td>
subset of tokens
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">VARIABLE_DEF</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PARAMETER_DEF">PARAMETER_DEF</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">METHOD_DEF</a>.
</td>
<td>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">VARIABLE_DEF</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PARAMETER_DEF">PARAMETER_DEF</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">METHOD_DEF</a>.
</td>
<td>3.2</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check so that it ignores getInstance() methods:
</p>
<source>
&lt;module name=&quot;IllegalType&quot;&gt;
&lt;property name=&quot;ignoredMethodNames&quot; value=&quot;getInstance&quot;/&gt;
&lt;/module&gt;
</source>
<p>
To configure the Check so that it verifies only public, protected and static
methods and fields:
</p>
<source>
&lt;module name=&quot;IllegalType&quot;&gt;
&lt;property name=&quot;memberModifiers&quot; value=&quot;LITERAL_PUBLIC,
LITERAL_PROTECTED, LITERAL_STATIC&quot;/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+IllegalType">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22illegal.type%22">
illegal.type</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="InnerAssignment">
<subsection name="Description">
<p>Since Checkstyle 3.0</p>
<p>
Checks for assignments in subexpressions, such as in <code>String s = Integer.toString(i = 2);</code>.
</p>
<p>
Rationale: With the exception of <code>for</code> iterators and assignment in
<code>while</code> idiom, all assignments should occur in their own top-level statement
to increase readability. With inner assignments like the one given above, it is difficult
to see all places where a variable is set.
</p>
<p>
Note: Check allows usage of the popular assignment in <code>while</code> idiom:
<source>
String line;
while ((line = bufferedReader.readLine()) != null) {
// process the line
}
</source>
Assignment inside a condition is not a problem here, as the assignment is surrounded by
an extra pair of parentheses. The comparison is <code>!= null</code> and there is no
chance that intention was to write <code>line == reader.readLine()</code>.
</p>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;InnerAssignment&quot;/&gt;
</source>
<p>
To configure the check for only <code>=</code>, <code> +=</code>, and <code>-=</code> operators:
</p>
<source>
&lt;module name=&quot;InnerAssignment&quot;&gt;
&lt;property name=&quot;tokens&quot; value=&quot;ASSIGN,PLUS_ASSIGN,MINUS_ASSIGN&quot;/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+InnerAssignment">
Sun Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+InnerAssignment">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22assignment.inner.avoid%22">
assignment.inner.avoid</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="MagicNumber">
<subsection name="Description">
<p>Since Checkstyle 3.1</p>
<p>
Checks that there are no <a href="https://en.wikipedia.org/wiki/Magic_number_%28programming%29">
&quot;magic numbers&quot;</a> where a magic
number is a numeric literal that is not defined as a constant.
By default, -1, 0, 1, and 2 are not considered to be magic numbers.
</p>
<p>
It is fine to have one constant defining multiple numeric literals within one expression:
<source>
static final int SECONDS_PER_DAY = 24 * 60 * 60;
static final double SPECIAL_RATIO = 4.0 / 3.0;
static final double SPECIAL_SUM = 1 + Math.E;
static final double SPECIAL_DIFFERENCE = 4 - Math.PI;
static final Border STANDARD_BORDER = BorderFactory.createEmptyBorder(3, 3, 3, 3);
static final Integer ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE = new Integer(42);
</source>
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>ignoreNumbers</td>
<td>non-magic numbers</td>
<td><a href="property_types.html#intSet">Number Set</a></td>
<td>-1, 0, 1, 2</td>
<td>3.1</td>
</tr>
<tr>
<td>ignoreHashCodeMethod</td>
<td>ignore magic numbers in hashCode methods</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><span class="default">false</span></td>
<td>5.3</td>
</tr>
<tr>
<td>ignoreAnnotation</td>
<td>ignore magic numbers in annotation declarations.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><span class="default">false</span></td>
<td>5.4</td>
</tr>
<tr>
<td>ignoreFieldDeclaration</td>
<td>ignore magic numbers in field declarations.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><span class="default">false</span></td>
<td>6.6</td>
</tr>
<tr>
<td>constantWaiverParentToken</td>
<td>Token that are allowed in the AST path from the number literal to the enclosing constant definition.</td>
<td>subset of tokens
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html">TokenTypes</a>
</td>
<td>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ASSIGN">ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ARRAY_INIT">ARRAY_INIT</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#EXPR">EXPR</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#UNARY_PLUS">UNARY_PLUS</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#UNARY_MINUS">UNARY_MINUS</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#TYPECAST">TYPECAST</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ELIST">ELIST</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_NEW">LITERAL_NEW</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_CALL">METHOD_CALL</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STAR">STAR</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#DIV">DIV</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PLUS">PLUS</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#MINUS">MINUS</a>.
</td>
<td>6.11</td>
</tr>
<tr>
<td>tokens</td>
<td>tokens to check</td>
<td>subset of tokens
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_DOUBLE">NUM_DOUBLE</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_FLOAT">NUM_FLOAT</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_INT">NUM_INT</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_LONG">NUM_LONG</a>.
</td>
<td>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_DOUBLE">NUM_DOUBLE</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_FLOAT">NUM_FLOAT</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_INT">NUM_INT</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_LONG">NUM_LONG</a>.
</td>
<td>3.1</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check with default configuration:
</p>
<source>
&lt;module name=&quot;MagicNumber&quot;/&gt;
</source>
<p>
results is following violations:
</p>
<source>
@MyAnnotation(6) // violation
class MyClass {
private field = 7; // violation
void foo() {
int i = i + 1; // no violation
int j = j + 8; // violation
}
}
</source>
<p>
To configure the check so that it checks floating-point numbers
that are not 0, 0.5, or 1:
</p>
<source>
&lt;module name=&quot;MagicNumber&quot;&gt;
&lt;property name=&quot;tokens&quot; value=&quot;NUM_DOUBLE, NUM_FLOAT&quot;/&gt;
&lt;property name=&quot;ignoreNumbers&quot; value=&quot;0, 0.5, 1&quot;/&gt;
&lt;property name=&quot;ignoreFieldDeclaration&quot; value=&quot;true&quot;/&gt;
&lt;property name=&quot;ignoreAnnotation&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
</source>
<p>
results is following violations:
</p>
<source>
@MyAnnotation(6) // no violation
class MyClass {
private field = 7; // no violation
void foo() {
int i = i + 1; // no violation
int j = j + 8; // violation
}
}
</source>
<p>
Config Example for constantWaiverParentToken Option:
</p>
<source>
&lt;module name=&quot;MagicNumber&quot;&gt;
&lt;property name=&quot;constantWaiverParentToken&quot; value=&quot;ASSIGN,ARRAY_INIT,EXPR,
UNARY_PLUS, UNARY_MINUS, TYPECAST, ELIST, DIV, PLUS &quot;/&gt;
&lt;/module&gt;
</source>
<p>result is following violation:</p>
<source>
class TestMethodCall {
public void method2() {
final TestMethodCall dummyObject = new TestMethodCall(62); //violation
final int a = 3; // ok as waiver is ASSIGN
final int [] b = {4, 5} // ok as waiver is ARRAY_INIT
final int c = -3; // ok as waiver is UNARY_MINUS
final int d = +4; // ok as waiver is UNARY_PLUS
final int e = method(1, 2) // ELIST is there but violation due to METHOD_CALL
final int x = 3 * 4; // violation
final int y = 3 / 4; // ok as waiver is DIV
final int z = 3 + 4; // ok as waiver is PLUS
final int w = 3 - 4; // violation
final int x = (int)(3.4); //ok as waiver is TYPECAST
}
}
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+MagicNumber">
Sun Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+MagicNumber">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22magic.number%22">
magic.number</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="MissingCtor">
<subsection name="Description">
<p>Since Checkstyle 3.4</p>
<p>
Checks that classes (except abstract ones) define a constructor and don't
rely on the default one.
</p>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;MissingCtor&quot;/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+MissingCtor">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22missing.ctor%22">
missing.ctor</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="MissingSwitchDefault">
<subsection name="Description">
<p>Since Checkstyle 3.1</p>
<p>
Checks that switch statement has a &quot;default&quot; clause.
</p>
<p>
Rationale: It's usually a good idea to introduce a default case in
every switch statement. Even if the developer is sure that all
currently possible cases are covered, this should be expressed in
the default branch, e.g. by using an assertion. This way the code is
protected against later changes, e.g. introduction of new types in an
enumeration type.
</p>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;MissingSwitchDefault&quot;/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+MissingSwitchDefault">
Google Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+MissingSwitchDefault">
Sun Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+MissingSwitchDefault">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22missing.switch.default%22">
missing.switch.default</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="ModifiedControlVariable">
<subsection name="Description">
<p>Since Checkstyle 3.5</p>
<p>
Check for ensuring that for loop control variables are not modified inside the for block. An example is:
</p>
<source>
for (int i = 0; i &lt; 1; i++) {
i++; //violation
}
</source>
<p>
Rationale: If the control variable is modified inside the loop
body, the program flow becomes more difficult to follow.<br/>
See <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.14">FOR statement</a> specification for more details.
</p>
<p>
Such loop would be suppressed:
</p>
<source>
for (int i = 0; i &lt; 10;) {
i++;
}
</source>
</subsection>
<subsection name="Properties">
<table>
<tr class="header">
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>skipEnhancedForLoopVariable</td>
<td>Controls whether to check <a href = "https://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.14.2">enhanced for-loop</a> variable.</td>
<td>
<a
href="property_types.html#boolean">Boolean</a>
</td>
<td>
<code>
false
</code>
</td>
<td>6.8</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;ModifiedControlVariable&quot;/&gt;
</source>
<p>
By default, This Check validates
<a href = "https://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.14.2">
Enhanced For-Loop</a>.
</p>
<p>
Option 'skipEnhancedForLoopVariable' could be used to skip check of variable
from Enhanced For Loop.
</p>
<p>
An example of how to configure the check so that it skips enhanced For Loop Variable is:
</p>
<source>
&lt;module name="ModifiedControlVariable"&gt;
&lt;property name="skipEnhancedForLoopVariable" value="true"/&gt;
&lt;/module&gt;
</source>
<p>Example:</p>
<p>
<source>
for ( String line: lines ) {
line = line.trim(); // it will skip this violation
}
</source>
</p>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+ModifiedControlVariable">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22modified.control.variable%22">
modified.control.variable</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="MultipleStringLiterals">
<subsection name="Description">
<p>Since Checkstyle 3.5</p>
<p>
Checks for multiple occurrences of the same string literal within a
single file.
</p>
<p>
Rationale: Code duplication makes maintenance more difficult, so it
can be better to replace the multiple occurrences with a constant.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>allowedDuplicates</td>
<td>
The maximum number of occurrences to allow without generating a
warning
</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td>1</td>
<td>3.5</td>
</tr>
<tr>
<td>ignoreStringsRegexp</td>
<td>
Regular expression pattern for ignored strings (with quotation marks)
</td>
<td><a href="property_types.html#regexp">Regular Expression</a></td>
<td><code>"^""$"</code></td>
<td>4.0</td>
</tr>
<tr>
<td>ignoreOccurrenceContext</td>
<td>
Token type names where duplicate strings are ignored even if they don't match
ignoredStringsRegexp. This allows you to exclude syntactical contexts like
annotations or static initializers from the check.
</td>
<td>
subset of tokens
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html">TokenTypes</a>
</td>
<td>
<code>ANNOTATION</code>
(ignore strings inside the context of an annotation)
</td>
<td>4.4</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;MultipleStringLiterals&quot;/&gt;
</source>
<p>
To configure the check so that it allows two occurrences of each
string:
</p>
<source>
&lt;module name=&quot;MultipleStringLiterals&quot;&gt;
&lt;property name=&quot;allowedDuplicates&quot; value=&quot;2&quot;/&gt;
&lt;/module&gt;
</source>
<p>
To configure the check so that it ignores ", " and empty strings:
</p>
<source>
&lt;module name=&quot;MultipleStringLiterals&quot;&gt;
&lt;property name=&quot;ignoreStringsRegexp&quot; value='^((&quot;&quot;)|(&quot;, &quot;))$'/&gt;
&lt;/module&gt;
</source>
<p>
To configure the check so that it flags duplicate strings in all
syntactical contexts, even in annotations like
<code>@SuppressWarnings("unchecked")</code>:
</p>
<source>
&lt;module name=&quot;MultipleStringLiterals&quot;&gt;
&lt;property name=&quot;ignoreOccurrenceContext&quot; value=&quot;&quot;/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+MultipleStringLiterals">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22multiple.string.literal%22">
multiple.string.literal</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="MultipleVariableDeclarations">
<subsection name="Description">
<p>Since Checkstyle 3.4</p>
<p>
Checks that each variable declaration is in its own statement and on
its own line.
</p>
<p>
Rationale: <a
href="http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-141270.html#2992">
the Java code conventions chapter 6.1</a> recommends that
declarations should be one per line/statement.
</p>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;MultipleVariableDeclarations&quot;/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+MultipleVariableDeclarations">
Google Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+MultipleVariableDeclarations">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22multiple.variable.declarations%22">
multiple.variable.declarations</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22multiple.variable.declarations.comma%22">
multiple.variable.declarations.comma</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="NestedForDepth">
<subsection name="Description">
<p>Since Checkstyle 5.3</p>
<p>
Restricts nested <code>for</code> blocks to a specified depth
(default = 1).
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>max</td>
<td>allowed nesting depth</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td><span class="default">1</span></td>
<td>5.3</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;NestedForDepth&quot;/&gt;
</source>
<p>
To configure the check to allow nesting depth 3:
</p>
<source>
&lt;module name=&quot;NestedForDepth&quot;&gt;
&lt;property name=&quot;max&quot; value=&quot;3&quot;/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+NestedForDepth">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22nested.for.depth%22">
nested.for.depth</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="NestedIfDepth">
<subsection name="Description">
<p>Since Checkstyle 3.2</p>
<p>
Restricts nested if-else blocks to a specified depth (default = 1).
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>max</td>
<td>allowed nesting depth</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td><code>1</code></td>
<td>3.2</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;NestedIfDepth&quot;/&gt;
</source>
<p>
To configure the check to allow nesting depth 3:
</p>
<source>
&lt;module name=&quot;NestedIfDepth&quot;&gt;
&lt;property name=&quot;max&quot; value=&quot;3&quot;/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+NestedIfDepth">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22nested.if.depth%22">
nested.if.depth</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="NestedTryDepth">
<subsection name="Description">
<p>Since Checkstyle 3.2</p>
<p>
Restricts nested try blocks to a specified depth (default = 1).
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>max</td>
<td>allowed nesting depth</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td><code>1</code></td>
<td>3.2</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;NestedTryDepth&quot;/&gt;
</source>
<p>
To configure the check to allow nesting depth 3:
</p>
<source>
&lt;module name=&quot;NestedTryDepth&quot;&gt;
&lt;property name=&quot;max&quot; value=&quot;3&quot;/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+NestedTryDepth">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22nested.try.depth%22">
nested.try.depth</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="NoClone">
<subsection name="Description">
<p>Since Checkstyle 5.0</p>
<p>
Checks that the clone method is not overridden from the
Object class.
</p>
<p>
Rationale: The clone method relies on strange, hard to follow rules that
are difficult to get right and do not work in all situations.
In some cases, either a copy constructor
or a static factory method can be used instead of the clone method
to return copies of an object.
For more information on rules for the clone method and its issues, see Effective Java:
Programming Language Guide First Edition by Joshua Bloch
pages 45-52.
</p>
<p>
This check is almost exactly the same as the {@link NoFinalizerCheck}
</p>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;NoClone&quot;/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+NoClone">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22avoid.clone.method%22">
avoid.clone.method</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="NoFinalizer">
<subsection name="Description">
<p>Since Checkstyle 5.0</p>
<p>
Verifies there are no <code>finalize()</code> methods
defined in a class.
</p>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;NoFinalizer&quot;/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+NoFinalizer">
Google Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+NoFinalizer">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22avoid.finalizer.method%22">
avoid.finalizer.method</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="OneStatementPerLine">
<subsection name="Description">
<p>Since Checkstyle 5.3</p>
<p>
Checks that there is only one statement per line.
</p>
<p>
Rationale: It's very difficult to read multiple statements on one line.
</p>
<p>
In the Java programming language, statements are the fundamental unit of
execution. All statements except blocks are terminated by a semicolon.
Blocks are denoted by open and close curly braces.
</p>
<p>
OneStatementPerLineCheck checks the following types of statements:
variable declaration statements, empty statements, import statements,
assignment statements, expression statements, increment statements,
object creation statements, 'for loop' statements, 'break' statements,
'continue' statements, 'return' statements.
</p>
</subsection>
<subsection name="Examples">
<p>
The following examples will be flagged as a violation:
</p>
<source>
//Each line causes violation:
int var1; int var2;
var1 = 1; var2 = 2;
int var1 = 1; int var2 = 2;
var1++; var2++;
Object obj1 = new Object(); Object obj2 = new Object();
import java.io.EOFException; import java.io.BufferedReader;
;; //two empty statements on the same line.
//Multi-line statements:
int var1 = 1
; var2 = 2; //violation here
int o = 1, p = 2,
r = 5; int t; //violation here
</source>
<p>
An example of how to configure this Check:
</p>
<source>
&lt;module name=&quot;OneStatementPerLine&quot;/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+OneStatementPerLine">
Google Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+OneStatementPerLine">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22multiple.statements.line%22">
multiple.statements.line</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="OverloadMethodsDeclarationOrder">
<subsection name="Description">
<p>Since Checkstyle 5.8</p>
<p>
Checks that overload methods are grouped together.
</p>
</subsection>
<subsection name="Examples">
<p>
Example of incorrect grouping overload methods:
</p>
<source>
public void foo(int i) {}
public void foo(String s) {}
public void notFoo() {} // Have to be after foo(int i, String s)
public void foo(int i, String s) {}
</source>
<p>
An example of how to configure the check is:
</p>
<source>
&lt;module name="OverloadMethodsDeclarationOrder"/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+OverloadMethodsDeclarationOrder">
Google Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+OverloadMethodsDeclarationOrder">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22overload.methods.declaration%22">
overload.methods.declaration</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="PackageDeclaration">
<subsection name="Description">
<p>Since Checkstyle 3.2</p>
<p>
Ensures that a class has a package declaration, and (optionally) whether
the package name matches the directory name for the source file.
</p>
<p>
Rationale: Classes that live in the null package cannot be
imported. Many novice developers are not aware of this.
</p>
<p>
Packages provide logical namespace to classes and should be stored in
the form of directory levels to provide physical grouping to your classes.
These directories are added to the classpath so that your classes
are visible to JVM when it runs the code.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>matchDirectoryStructure</td>
<td>Whether to check for directory and package name match.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><code>true</code></td>
<td>7.6.1</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;PackageDeclaration&quot;/&gt;
</source>
<p>
Let us consider the class AnnotationLocationCheck which is in the directory
/com/puppycrawl/tools/checkstyle/checks/annotations/
</p>
<source>
package com.puppycrawl.tools.checkstyle.checks; //Violation
public class AnnotationLocationCheck extends AbstractCheck {
//...
}
</source>
<p>
Example of how the check works when matchDirectoryStructure option is set to false.
Let us again consider the AnnotationLocationCheck class located at directory
/com/puppycrawl/tools/checkstyle/checks/annotations/ along with the following setup,
</p>
<source>
&lt;module name=&quot;PackageDeclaration&quot;&gt;
&lt;property name=&quot;matchDirectoryStructure&quot; value=&quot;false&quot;/&gt;
&lt;/module&gt;
</source>
<source>
package com.puppycrawl.tools.checkstyle.checks; //No Violation
public class AnnotationLocationCheck extends AbstractCheck {
//...
}
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+PackageDeclaration">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22mismatch.package.directory%22">
mismatch.package.directory</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22missing.package.declaration%22">
missing.package.declaration</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="ParameterAssignment">
<subsection name="Description">
<p>Since Checkstyle 3.2</p>
<p> Disallows assignment of parameters.</p>
<p>
Rationale: Parameter assignment is often considered poor programming
practice. Forcing developers to declare parameters as final is often
onerous. Having a check ensure that parameters are never assigned
would give the best of both worlds.
</p>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;ParameterAssignment&quot;/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+ParameterAssignment">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22parameter.assignment%22">
parameter.assignment</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="RequireThis">
<subsection name="Description">
<p>Since Checkstyle 3.4</p>
<p>
Checks that references to instance variables and methods of the present
object are explicitly of the form &quot;this.varName&quot; or
&quot;this.methodName(args)&quot; and that those references don't
rely on the default behavior when &quot;this.&quot; is absent.
</p>
<p>
Warning: the Check is very controversial if 'validateOnlyOverlapping' option is set to
'false' and not that actual nowadays.
</p>
<p>
Rationale:
</p>
<ol>
<li>
The same notation/habit for C++ and Java (C++ have global methods, so having
&quot;this.&quot; do make sense in it to distinguish call of method of class
instead of global).
</li>
<li>
Non-IDE development (ease of refactoring, some clearness to distinguish
static and non-static methods).
</li>
</ol>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>checkFields</td>
<td>Whether to check references to fields.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><code>true</code></td>
<td>3.4</td>
</tr>
<tr>
<td>checkMethods</td>
<td>Whether to check references to methods.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><code>true</code></td>
<td>3.4</td>
</tr>
<tr>
<td>validateOnlyOverlapping</td>
<td>Whether to check only overlapping by variables or arguments.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><code>true</code></td>
<td>6.17</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the default check:
</p>
<source>
&lt;module name=&quot;RequireThis&quot;/&gt;
</source>
<p>
To configure to check the <code>this</code> qualifier for fields only:
</p>
<source>
&lt;module name="RequireThis"&gt;
&lt;property name=&quot;checkMethods&quot; value=&quot;false&quot;/&gt;
&lt;/module&gt;
</source>
<p>
Examples of how the check works if validateOnlyOverlapping option is set to true:
</p>
<source>
public static class A {
private int field1;
private int field2;
public A(int field1) {
// Overlapping by constructor argument.
field1 = field1; // violation: Reference to instance variable "field1" needs "this".
field2 = 0;
}
void foo3() {
String field1 = "values";
// Overlapping by local variable.
field1 = field1; // violation: Reference to instance variable "field1" needs "this".
}
}
public static class B {
private int field1;
public A(int f) {
field1 = f;
}
String addSuffixToField(String field1) {
// Overlapping by method argument. Equal to "return field1 = field1 + "suffix";"
return field1 += "suffix"; // violation: Reference to instance variable "field1" needs "this".
}
}
</source>
<p>
Please, be aware of the following logic, which is implemented in the check:
</p>
<p>
1) If you arrange 'this' in your code on your own, the check will not raise violation for
variables which use 'this' to reference a class field, for example:
</p>
<source>
public class C {
private int scale;
private int x;
public void foo(int scale) {
scale = this.scale; // no violation
if (scale > 0) {
scale = -scale; // no violation
}
x *= scale;
}
}
</source>
<p>
2) If method parameter is returned from the method, the check will not raise violation for
returned variable/parameter, for example:
</p>
<source>
public class D {
private String prefix;
public String modifyPrefix(String prefix) {
prefix = "^" + prefix + "$" // no violation (modification of parameter)
return prefix; // modified method parameter is returned from the method
}
}
</source>
<p>
Examples of how the check works if validateOnlyOverlapping option is set to false:
</p>
<source>
public static class A {
private int field1;
private int field2;
public A(int field1) {
field1 = field1; // violation: Reference to instance variable "field1" needs "this".
field2 = 0; // violation: Reference to instance variable "field2" needs "this".
String field2;
field2 = "0"; // No violation. Local var allowed
}
void foo3() {
String field1 = "values";
field1 = field1; // violation: Reference to instance variable "field1" needs "this".
}
}
public static class B {
private int field1;
public A(int f) {
field1 = f; // violation: Reference to instance variable "field1" needs "this".
}
String addSuffixToField(String field1) {
return field1 += "suffix"; // violation: Reference to instance variable "field1" needs "this".
}
}
// If the variable is locally defined, there won't be a violation provided the variable doesn't overlap.
class C {
private String s1 = "foo1";
String s2 = "foo2";
C() {
s1 = "bar1"; // Violation. Reference to instance variable 's1' needs "this.".
String s2;
s2 = "bar2"; // No violation. Local var allowed.
s2 += s2; // Violation. Overlapping. Reference to instance variable 's2' needs "this.".
}
}
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+RequireThis">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22require.this.method%22">
require.this.method</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22require.this.variable%22">
require.this.variable</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="ReturnCount">
<subsection name="Description">
<p>Since Checkstyle 3.2</p>
<p>
Restricts the number of return statements in methods, constructors and lambda expressions
(2 by default). Ignores specified methods (<code>equals()</code> by default).
</p>
<p>
<b>max</b> property will only check returns in methods and lambdas that return a specific value (Ex: 'return 1;').
</p>
<p>
<b>maxForVoid</b> property will only check returns in methods, constructors, and lambdas that have no return type (IE
'return;').
It will only count visible return statements. Return statements not normally written, but implied, at
the end of the method/constructor definition will not be taken into account.
To disallow "return;" in void return type methods, use a value of 0.
</p>
<p>
Rationale: Too many return points can mean that code is
attempting to do too much or may be difficult to understand.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>max</td>
<td>maximum allowed number of return statements in non-void methods/lambdas</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td><code>2</code></td>
<td>3.2</td>
</tr>
<tr>
<td>maxForVoid</td>
<td>maximum allowed number of return statements in void methods/constructors/lambdas</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td><code>1</code></td>
<td>6.19</td>
</tr>
<tr>
<td>format</td>
<td>method names to ignore</td>
<td><a href="property_types.html#regexp">Regular Expression</a></td>
<td><code>"^equals$"</code></td>
<td>3.4</td>
</tr>
<tr>
<td>tokens</td>
<td>tokens to check</td>
<td>
subset of tokens
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">CTOR_DEF</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">METHOD_DEF</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LAMBDA">LAMBDA</a>.
</td>
<td>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">CTOR_DEF</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">METHOD_DEF</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LAMBDA">LAMBDA</a>.
</td>
<td>3.2</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check so that it doesn't allow more than three
return statements per method (ignoring the <code>equals()</code>
method):
</p>
<source>
&lt;module name=&quot;ReturnCount&quot;&gt;
&lt;property name=&quot;max&quot; value=&quot;3&quot;/&gt;
&lt;/module&gt;
</source>
<p>
To configure the check so that it doesn't allow any
return statements per void method:
</p>
<source>
&lt;module name=&quot;ReturnCount&quot;&gt;
&lt;property name=&quot;maxForVoid&quot; value=&quot;0&quot;/&gt;
&lt;/module&gt;
</source>
<p>
To configure the check so that it doesn't allow more than 2
return statements per method (ignoring the <code>equals()</code>
method) and more than 1 return statements per void method:
</p>
<source>
&lt;module name=&quot;ReturnCount&quot;&gt;
&lt;property name=&quot;max&quot; value=&quot;2&quot;/&gt;
&lt;property name=&quot;maxForVoid&quot; value=&quot;1&quot;/&gt;
&lt;/module&gt;
</source>
<p>
To configure the check so that it doesn't allow more than three
return statements per method for all methods:
</p>
<source>
&lt;module name=&quot;ReturnCount&quot;&gt;
&lt;property name=&quot;max&quot; value=&quot;3&quot;/&gt;
&lt;property name=&quot;format&quot; value=&quot;^$&quot;/&gt;
&lt;/module&gt;
</source>
<p>
To configure the check so that it doesn't allow any return statements
in constructors, more than one return statement in all lambda
expressions and more than two return statements in methods:
</p>
<source>
&lt;module name=&quot;ReturnCount&quot;&gt;
&lt;property name=&quot;max&quot; value=&quot;0&quot;/&gt;
&lt;property name=&quot;tokens&quot; value=&quot;CTOR_DEF&quot;/&gt;
&lt;/module&gt;
&lt;module name=&quot;ReturnCount&quot;&gt;
&lt;property name=&quot;max&quot; value=&quot;1&quot;/&gt;
&lt;property name=&quot;tokens&quot; value=&quot;LAMBDA&quot;/&gt;
&lt;/module&gt;
&lt;module name=&quot;ReturnCount&quot;&gt;
&lt;property name=&quot;max&quot; value=&quot;2&quot;/&gt;
&lt;property name=&quot;tokens&quot; value=&quot;METHOD_DEF&quot;/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+ReturnCount">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22return.count%22">
return.count</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22return.countVoid%22">
return.countVoid</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="SimplifyBooleanExpression">
<subsection name="Description">
<p>Since Checkstyle 3.0</p>
<p>
Checks for over-complicated boolean expressions. Currently finds
code like <code> if (b == true)</code>, <code>b || true</code>, <code>!false</code>,
etc.
</p>
<p>
Rationale: Complex boolean logic makes code hard to understand and
maintain.
</p>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;SimplifyBooleanExpression&quot;/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SimplifyBooleanExpression">
Sun Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SimplifyBooleanExpression">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22simplify.expression%22">
simplify.expression</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="SimplifyBooleanReturn">
<subsection name="Description">
<p>Since Checkstyle 3.0</p>
<p>
Checks for over-complicated boolean return statements. For example
the following code
</p>
<source>
if (valid())
return false;
else
return true;
</source>
<p>
could be written as
</p>
<source>
return !valid();
</source>
<p>
The idea for this Check has been shamelessly stolen from the
equivalent <a href="http://pmd.sourceforge.net">PMD</a> rule.
</p>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;SimplifyBooleanReturn&quot;/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SimplifyBooleanReturn">
Sun Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SimplifyBooleanReturn">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22simplify.boolReturn%22">
simplify.boolReturn</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="StringLiteralEquality">
<subsection name="Description">
<p>Since Checkstyle 3.2</p>
<p>
Checks that string literals are not used with <code>==</code> or
<code>&#33;=</code>.
</p>
<p>
Rationale: Novice Java programmers often use code like:
</p>
<source>
if (x == &quot;something&quot;)
</source>
<p>when they mean</p>
<source>
if (&quot;something&quot;.equals(x))
</source>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;StringLiteralEquality&quot;/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+StringLiteralEquality">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22string.literal.equality%22">
string.literal.equality</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="SuperClone">
<subsection name="Description">
<p>Since Checkstyle 3.2</p>
<p>
Checks that an overriding <code>clone()</code> method invokes
<code>super.clone()</code>. Does not check native methods, as
they have no possible java defined implementation.
</p>
<p>
Reference: <a
href="https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#clone%28%29">Object.clone()</a>.
</p>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;SuperClone&quot;/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuperClone">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22missing.super.call%22">
missing.super.call</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="SuperFinalize">
<subsection name="Description">
<p>Since Checkstyle 3.2</p>
<p>
Checks that an overriding <code>finalize()</code> method invokes
<code>super.finalize()</code>. Does not check native methods, as
they have no possible java defined implementation.
</p>
<p>
Reference: <a
href="http://www.oracle.com/technetwork/java/javamail/finalization-137655.html">
Use Finalization Only When You Must</a>.
</p>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;SuperFinalize&quot;/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuperFinalize">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22missing.super.call%22">
missing.super.call</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="UnnecessaryParentheses">
<subsection name="Description">
<p>Since Checkstyle 3.4</p>
<p>
Checks for the use of unnecessary parentheses.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>tokens</td>
<td>tokens to check</td>
<td>
subset of tokens
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#EXPR">EXPR</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#IDENT">IDENT</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_DOUBLE">NUM_DOUBLE</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_FLOAT">NUM_FLOAT</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_INT">NUM_INT</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_LONG">NUM_LONG</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STRING_LITERAL">STRING_LITERAL</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_NULL">LITERAL_NULL</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FALSE">LITERAL_FALSE</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_TRUE">LITERAL_TRUE</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ASSIGN">ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BAND_ASSIGN">BAND_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BOR_ASSIGN">BOR_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BSR_ASSIGN">BSR_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BXOR_ASSIGN">BXOR_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#DIV_ASSIGN">DIV_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#MINUS_ASSIGN">MINUS_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#MOD_ASSIGN">MOD_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PLUS_ASSIGN">PLUS_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#SL_ASSIGN">SL_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#SR_ASSIGN">SR_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STAR_ASSIGN">STAR_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LAMBDA">LAMBDA</a>.
</td>
<td>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#EXPR">EXPR</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#IDENT">IDENT</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_DOUBLE">NUM_DOUBLE</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_FLOAT">NUM_FLOAT</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_INT">NUM_INT</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#NUM_LONG">NUM_LONG</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STRING_LITERAL">STRING_LITERAL</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_NULL">LITERAL_NULL</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FALSE">LITERAL_FALSE</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_TRUE">LITERAL_TRUE</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ASSIGN">ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BAND_ASSIGN">BAND_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BOR_ASSIGN">BOR_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BSR_ASSIGN">BSR_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BXOR_ASSIGN">BXOR_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#DIV_ASSIGN">DIV_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#MINUS_ASSIGN">MINUS_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#MOD_ASSIGN">MOD_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PLUS_ASSIGN">PLUS_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#SL_ASSIGN">SL_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#SR_ASSIGN">SR_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STAR_ASSIGN">STAR_ASSIGN</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LAMBDA">LAMBDA</a>.
</td>
<td>3.4</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;UnnecessaryParentheses&quot;/&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+UnnecessaryParentheses">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22unnecessary.paren.assign%22">
unnecessary.paren.assign</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22unnecessary.paren.expr%22">
unnecessary.paren.expr</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22unnecessary.paren.ident%22">
unnecessary.paren.ident</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22unnecessary.paren.lambda%22">
unnecessary.paren.lambda</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22unnecessary.paren.literal%22">
unnecessary.paren.literal</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22unnecessary.paren.return%22">
unnecessary.paren.return</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22unnecessary.paren.string%22">
unnecessary.paren.string</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="VariableDeclarationUsageDistance">
<subsection name="Description">
<p>Since Checkstyle 5.8</p>
<p>
Checks the distance between declaration of variable and its first usage.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>allowedDistance</td>
<td>A distance between declaration of variable and its first usage. Values should be greater than 0.</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td>3</td>
<td>5.8</td>
</tr>
<tr>
<td>ignoreVariablePattern</td>
<td>pattern for ignoring the distance calculation</td>
<td><a href="property_types.html#regexp">Regular Expression</a></td>
<td><code>""</code></td>
<td>5.8</td>
</tr>
<tr>
<td>validateBetweenScopes</td>
<td>Allows to calculate the distance between declaration of variable and its first usage in the different scopes.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><code>false</code></td>
<td>5.8</td>
</tr>
<tr>
<td>ignoreFinal</td>
<td>Allows to ignore variables with a 'final' modifier.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><code>true</code></td>
<td>5.8</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
Example #1:
</p>
<source>
int count;
a = a + b;
b = a + a;
count = b; // DECLARATION OF VARIABLE 'count'
// SHOULD BE HERE (distance = 3)
</source>
<p>
Example #2:
</p>
<source>
int count;
{
a = a + b;
count = b; // DECLARATION OF VARIABLE 'count'
// SHOULD BE HERE (distance = 2)
}
</source>
<p>
Check can detect a block of initialization methods. If a variable is used in
such a block and there is no other statements after this variable then distance=1.
</p>
<p>
Case #1:
</p>
<source>
int minutes = 5;
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(timeNow);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.HOUR_OF_DAY, hh);
cal.set(Calendar.MINUTE, minutes);
</source>
<p>
The distance for the variable minutes is 1 even
though this variable is used in the fifth method's call.
</p>
<p>
Case #2:
</p>
<source>
int minutes = 5;
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(timeNow);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
System.out.println(cal);
cal.set(Calendar.HOUR_OF_DAY, hh);
cal.set(Calendar.MINUTE, minutes);
</source>
<p>
The distance for the variable minutes is 6 because there is one more expression
(except the initialization block) between the declaration of this variable and its usage.
</p>
<p>
An example how to configure this Check:
</p>
<source>
&lt;module name="VariableDeclarationUsageDistance"/&gt;
</source>
<p>
An example of how to configure this Check:
- to set the allowed distance to 4;
- to ignore variables with prefix '^temp';
- to force the validation between scopes;
- to check the final variables;
</p>
<source>
&lt;module name="VariableDeclarationUsageDistance"&gt;
&lt;property name="allowedDistance" value="4"/&gt;
&lt;property name="ignoreVariablePattern" value="^temp.*"/&gt;
&lt;property name="validateBetweenScopes" value="true"/&gt;
&lt;property name="ignoreFinal" value="false"/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Notes">
<p>
ATTENTION!! (Not supported cases)
</p>
<source>
Case #1:
{
int c;
int a = 3;
int b = 2;
{
a = a + b;
c = b;
}
}
</source>
<p>
Distance for variable 'a' = 1;
Distance for variable 'b' = 1;
Distance for variable 'c' = 2.
</p>
<p>
As distance by default is 1 the Check doesn't raise warning for
variables 'a' and 'b' to move them into the block.
</p>
<p>
Case #2:
</p>
<source>
int sum = 0;
for (int i = 0; i &lt; 20; i++) {
a++;
b--;
sum++;
if (sum > 10) {
res = true;
}
}
</source>
<p>
Distance for variable 'sum' = 3.
</p>
<p>
As the distance is more then the default one, the Check
raises warning for variable 'sum' to move it into the 'for(...)' block.
But there is situation when variable 'sum' hasn't to be 0 within each iteration.
So, to avoid such warnings you can use Suppression Filter, provided by
Checkstyle, for the whole class.
</p>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+VariableDeclarationUsageDistance">
Google Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+VariableDeclarationUsageDistance">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22variable.declaration.usage.distance%22">
variable.declaration.usage.distance</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fcoding+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22variable.declaration.usage.distance.extend%22">
variable.declaration.usage.distance.extend</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.coding
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
</body>
</document>