
edu.hm.hafner.analysis.parser.checkstyle.config_coding.xml Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of analysis-model Show documentation
Show all versions of analysis-model Show documentation
This library provides a Java object model to read, aggregate, filter, and query static analysis reports.
It is used by Jenkins' warnings next generation plug-in to visualize the warnings of individual builds.
Additionally, this library is used by a GitHub action to autograde student software projects based on a given set of
metrics (unit tests, code and mutation coverage, static analysis warnings).
<?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" id="ArrayTrailingComma_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" id="ArrayTrailingComma_Examples"> <p> To configure the check: </p> <source> <module name="ArrayTrailingComma"/> </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" id="ArrayTrailingComma_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" id="ArrayTrailingComma_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" id="ArrayTrailingComma_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="ArrayTrailingComma_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="AvoidInlineConditionals"> <subsection name="Description" id="AvoidInlineConditionals_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<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" id="AvoidInlineConditionals_Examples"> <p> To configure the check: </p> <source> <module name="AvoidInlineConditionals"/> </source> </subsection> <subsection name="Example of Usage" id="AvoidInlineConditionals_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" id="AvoidInlineConditionals_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" id="AvoidInlineConditionals_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="AvoidInlineConditionals_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="CovariantEquals"> <subsection name="Description" id="CovariantEquals_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" id="CovariantEquals_Examples"> <p> To configure the check: </p> <source> <module name="CovariantEquals"/> </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" id="CovariantEquals_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" id="CovariantEquals_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" id="CovariantEquals_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="CovariantEquals_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="DeclarationOrder"> <subsection name="Description" id="DeclarationOrder_Description"> <p>Since Checkstyle 3.2</p> <p> According to <a href="https://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" id="DeclarationOrder_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" id="DeclarationOrder_Examples"> <p> To configure the check: </p> <source> <module name="DeclarationOrder"/> </source> <p> For example: <source> class K { int a; void m(){} K(){} <-- "Constructor definition in wrong order" int b; <-- "Instance variable definition in wrong order" } </source> </p> <p> With <b>ignoreConstructors</b> option: <source> class K { int a; void m(){} K(){} int b; <-- "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; <-- "Instance variable definition in wrong order" } </source> </p> </subsection> <subsection name="Example of Usage" id="DeclarationOrder_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" id="DeclarationOrder_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" id="DeclarationOrder_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="DeclarationOrder_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="DefaultComesLast"> <subsection name="Description" id="DefaultComesLast_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" id="DefaultComesLast_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" id="DefaultComesLast_Examples"> <p> To configure the check: </p> <source> <module name="DefaultComesLast"/> </source> <p> To configure the check for skipIfLastAndSharedWithCase: </p> <source> <module name="DefaultComesLast"> <property name="skipIfLastAndSharedWithCase" value="true"/> </module> </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" id="DefaultComesLast_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" id="DefaultComesLast_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" id="DefaultComesLast_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="DefaultComesLast_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="EmptyStatement"> <subsection name="Description" id="EmptyStatement_Description"> <p>Since Checkstyle 3.1</p> <p> Detects empty statements (standalone ";" semicolon). </p> </subsection> <subsection name="Examples" id="EmptyStatement_Examples"> <p> To configure the check: </p> <source> <module name="EmptyStatement"/> </source> </subsection> <subsection name="Example of Usage" id="EmptyStatement_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" id="EmptyStatement_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" id="EmptyStatement_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="EmptyStatement_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="EqualsAvoidNull"> <subsection name="Description" id="EqualsAvoidNull_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("My_Sweet_String"); </source> <p>should be refactored to:</p> <source> String nullString = null; "My_Sweet_String".equals(nullString); </source> </subsection> <subsection name="Properties" id="EqualsAvoidNull_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" id="EqualsAvoidNull_Examples"> <p> To configure the check: </p> <source> <module name="EqualsAvoidNull"/> </source> </subsection> <subsection name="Example of Usage" id="EqualsAvoidNull_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" id="EqualsAvoidNull_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" id="EqualsAvoidNull_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="EqualsAvoidNull_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="EqualsHashCode"> <subsection name="Description" id="EqualsHashCode_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" id="EqualsHashCode_Examples"> <p> To configure the check: </p> <source> <module name="EqualsHashCode"/> </source> </subsection> <subsection name="Example of Usage" id="EqualsHashCode_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" id="EqualsHashCode_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" id="EqualsHashCode_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="EqualsHashCode_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="ExplicitInitialization"> <subsection name="Description" id="ExplicitInitialization_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" id="ExplicitInitialization_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" id="ExplicitInitialization_Examples"> <p> To configure the check: </p> <source> <module name="ExplicitInitialization"/> </source> <p> To configure the check so that it only checks for objects that explicitly initialize to null: </p> <source> <module name="ExplicitInitialization"> <property name="onlyObjectReferences" value="true"/> </module> </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<String> bar = null; // violation private Bar<String>[] barArray = null; // violation public static void main( String [] args ) { } } </source> </p> </subsection> <subsection name="Example of Usage" id="ExplicitInitialization_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" id="ExplicitInitialization_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" id="ExplicitInitialization_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="ExplicitInitialization_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="FallThrough"> <subsection name="Description" id="FallThrough_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" id="FallThrough_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" id="FallThrough_Examples"> <p> To configure the check: </p> <source> <module name="FallThrough"/> </source> <p> or </p> <source> <module name="FallThrough"> <property name="reliefPattern" value="continue in next case"/> </module> </source> </subsection> <subsection name="Example of Usage" id="FallThrough_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" id="FallThrough_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" id="FallThrough_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="FallThrough_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="FinalLocalVariable"> <subsection name="Description" id="FinalLocalVariable_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" id="FinalLocalVariable_Notes"> <p> When configured to check parameters, the check ignores parameters of interface methods and abstract methods. </p> </subsection> <subsection name="Properties" id="FinalLocalVariable_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" id="FinalLocalVariable_Examples"> <p> To configure the check: </p> <source> <module name="FinalLocalVariable"/> </source> <p> To configure the check so that it checks local variables and parameters: </p> <source> <module name="FinalLocalVariable"> <property name="tokens" value="VARIABLE_DEF,PARAMETER_DEF"/> </module> </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> <module name="FinalLocalVariable"> <property name="tokens" value="VARIABLE_DEF"/> <property name="validateEnhancedForLoopVariable" value="true"/> </module> </source> <p>Example:</p> <p> <source> for (int number : myNumbers) { // violation System.out.println(number); } </source> </p> <p> An example of how to configure check on local variables and parameters but do not validate loop variables: </p> <source> <module name="FinalLocalVariable"> <property name="tokens" value="VARIABLE_DEF,PARAMETER_DEF"/> <property name="validateEnhancedForLoopVariable" value="false"/> </module> </source> <p>Example:</p> <p> <source> public class MyClass { static int foo(int x, int y) { //violations, parameters should be final return x+y; } public static void main (String []args) { //violation, parameters should be final for (String i : args) { System.out.println(i); } int result=foo(1,2); // violation } } </source> </p> </subsection> <subsection name="Example of Usage" id="FinalLocalVariable_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" id="FinalLocalVariable_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" id="FinalLocalVariable_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="FinalLocalVariable_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="HiddenField"> <subsection name="Description" id="HiddenField_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" id="HiddenField_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 "xyz" has name "setXyz", one parameter named "xyz" 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" id="HiddenField_Examples"> <p> To configure the check: </p> <source> <module name="HiddenField"/> </source> <p> To configure the check so that it checks local variables but not parameters: </p> <source> <module name="HiddenField"> <property name="tokens" value="VARIABLE_DEF"/> </module> </source> <p> To configure the check so that it ignores the variables and parameters named "test": </p> <source> <module name="HiddenField"> <property name="ignoreFormat" value="^test$"/> </module> </source> <source> class SomeClass { private List<String> test; private void addTest(List<String> test) // no violation { this.test.addAll(test); } private void foo() { final List<String> test = new ArrayList<>(); // no violation ... } } </source> <p> To configure the check so that it ignores constructor parameters: </p> <source> <module name="HiddenField"> <property name="ignoreConstructorParameter" value="true"/> </module> </source> <p> To configure the check so that it ignores the parameter of setter methods: </p> <source> <module name="HiddenField"> <property name="ignoreSetter" value="true"/> </module> </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> <module name="HiddenField"> <property name="ignoreSetter" value="true"/> <property name="setterCanReturnItsClass" value="true"/> </module> </source> </subsection> <subsection name="Example of Usage" id="HiddenField_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" id="HiddenField_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" id="HiddenField_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="HiddenField_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="IllegalCatch"> <subsection name="Description" id="IllegalCatch_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" id="IllegalCatch_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>java.lang.Throwable, RuntimeException, Error, Throwable, java.lang.Error, java.lang.RuntimeException, Exception, java.lang.Exception</code></td> <td>3.2</td> </tr> </table> </subsection> <subsection name="Examples" id="IllegalCatch_Examples"> <p> To configure the check: </p> <source> <module name="IllegalCatch"/> </source> </subsection> <subsection name="Example of Usage" id="IllegalCatch_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" id="IllegalCatch_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" id="IllegalCatch_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="IllegalCatch_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="IllegalInstantiation"> <subsection name="Description" id="IllegalInstantiation_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" id="IllegalInstantiation_Notes"> <p> There is a limitation that it is currently not possible to specify array classes. </p> </subsection> <subsection name="Properties" id="IllegalInstantiation_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" id="IllegalInstantiation_Examples"> <p> To configure the check to find instantiations of java.lang.Boolean: </p> <source> <module name="IllegalInstantiation"> <property name="classes" value="java.lang.Boolean"/> </module> </source> </subsection> <subsection name="Example of Usage" id="IllegalInstantiation_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" id="IllegalInstantiation_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" id="IllegalInstantiation_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="IllegalInstantiation_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="IllegalThrows"> <subsection name="Description" id="IllegalThrows_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" id="IllegalThrows_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>java.lang.Throwable, RuntimeException, Error, Throwable, java.lang.Error, java.lang.RuntimeException</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" id="IllegalThrows_Examples"> <p> To configure the check: </p> <source> <module name="IllegalThrows"/> </source> <p> To configure the check rejecting throws NullPointerException from methods: </p> <source> <module name="IllegalThrows"> <property name="illegalClassNames" value="NullPointerException"/> </module> </source> <p> To configure the check ignoring method named "foo()": </p> <source> <module name="IllegalThrows"> <property name="ignoredMethodNames" value="foo"/> </module> </source> <p> To configure the check to warn on overridden methods: </p> <source> <module name="IllegalThrows"> <property name="ignoreOverriddenMethods" value="false"/> </module> </source> </subsection> <subsection name="Example of Usage" id="IllegalThrows_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" id="IllegalThrows_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" id="IllegalThrows_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="IllegalThrows_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="IllegalToken"> <subsection name="Description" id="IllegalToken_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" id="IllegalToken_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" id="IllegalToken_Examples"> <p> To configure the check to find token LITERAL_NATIVE: </p> <source> <module name="IllegalToken"> <property name="tokens" value="LITERAL_NATIVE"/> </module> </source> </subsection> <subsection name="Example of Usage" id="IllegalToken_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" id="IllegalToken_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" id="IllegalToken_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="IllegalToken_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="IllegalTokenText"> <subsection name="Description" id="IllegalTokenText_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" id="IllegalTokenText_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>"^$" (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>""</code></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" id="IllegalTokenText_Examples"> <p> To configure the check to forbid String literals containing <code>"a href"</code>: </p> <source> <module name="IllegalTokenText"> <property name="tokens" value="STRING_LITERAL"/> <property name="format" value="a href"/> </module> </source> <p> To configure the check to forbid leading zeros in an integer literal, other than zero and a hex literal: </p> <source> <module name="IllegalTokenText"> <property name="tokens" value="NUM_INT,NUM_LONG"/> <property name="format" value="^0[^lx]"/> <property name="ignoreCase" value="true"/> </module> </source> </subsection> <subsection name="Example of Usage" id="IllegalTokenText_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" id="IllegalTokenText_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" id="IllegalTokenText_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="IllegalTokenText_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="IllegalType"> <subsection name="Description" id="IllegalType_Description"> <p>Since Checkstyle 3.2</p> <p> Checks that particular classes or interfaces are never used. </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" id="IllegalType_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>LinkedHashSet, java.util.HashSet, java.util.LinkedHashMap, java.util.TreeMap, HashMap, TreeSet, java.util.HashMap, TreeMap, java.util.LinkedHashSet, java.util.TreeSet, HashSet, LinkedHashMap</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> <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>getInitialContext, getEnvironment</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>To check only methods and fields with any of the specified modifiers. This property does not affect method calls nor method references.</td> <td>subset of tokens <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html">TokenTypes</a></td> <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#ANNOTATION_FIELD_DEF"> ANNOTATION_FIELD_DEF</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#METHOD_DEF"> METHOD_DEF</a>, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_REF"> METHOD_REF</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#VARIABLE_DEF"> VARIABLE_DEF</a>. </td> <td> <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ANNOTATION_FIELD_DEF"> ANNOTATION_FIELD_DEF</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#METHOD_DEF"> METHOD_DEF</a>, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_REF"> METHOD_REF</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#VARIABLE_DEF"> VARIABLE_DEF</a>. </td> <td>3.2</td> </tr> </table> </subsection> <subsection name="Examples" id="IllegalType_Examples"> <p> To configure the check so that it ignores getInstance() methods: </p> <source> <module name="IllegalType"> <property name="ignoredMethodNames" value="getInstance"/> </module> </source> <p> To configure the Check so that it verifies only public, protected or static methods and fields: </p> <source> <module name="IllegalType"> <property name="memberModifiers" value="LITERAL_PUBLIC, LITERAL_PROTECTED, LITERAL_STATIC"/> </module> </source> <p> To configure the check so that it verifies usage of types Boolean and Foo: </p> <source> <module name="IllegalType"> <property name="illegalClassNames" value="Boolean, Foo"/> </module> </source> <source> public class Test { public Set<Boolean> set; // violation public java.util.List<Map<Boolean, Foo>> list; // violation private void method(List<Foo> list, Boolean value) { // violation SomeType.<Boolean>foo(); // violation final Consumer<Foo> consumer = Foo<Boolean>::foo; // violation } public <T extends Boolean, U extends Serializable> void typeParameter(T a) {} // violation public void fullName(java.util.ArrayList<? super Boolean> a) {} // violation public abstract Set<Boolean> shortName(Set<? super Boolean> a); // violation public Set<? extends Foo> typeArgument() { // violation return new TreeSet<Foo<Boolean>>(); } } </source> </subsection> <subsection name="Example of Usage" id="IllegalType_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" id="IllegalType_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" id="IllegalType_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="IllegalType_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="InnerAssignment"> <subsection name="Description" id="InnerAssignment_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" id="InnerAssignment_Examples"> <p> To configure the check: </p> <source> <module name="InnerAssignment"/> </source> <p> To configure the check for only <code>=</code>, <code> +=</code>, and <code>-=</code> operators: </p> <source> <module name="InnerAssignment"> <property name="tokens" value="ASSIGN,PLUS_ASSIGN,MINUS_ASSIGN"/> </module> </source> </subsection> <subsection name="Example of Usage" id="InnerAssignment_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" id="InnerAssignment_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" id="InnerAssignment_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="InnerAssignment_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="MagicNumber"> <subsection name="Description" id="MagicNumber_Description"> <p>Since Checkstyle 3.1</p> <p> Checks that there are no <a href="https://en.wikipedia.org/wiki/Magic_number_%28programming%29"> "magic numbers"</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" id="MagicNumber_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#TYPECAST"> TYPECAST</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#EXPR"> EXPR</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#UNARY_MINUS"> UNARY_MINUS</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#ELIST"> ELIST</a>, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STAR"> STAR</a>, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ASSIGN"> ASSIGN</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>, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#DIV"> DIV</a>, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_NEW"> LITERAL_NEW</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" id="MagicNumber_Examples"> <p> To configure the check with default configuration: </p> <source> <module name="MagicNumber"/> </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> <module name="MagicNumber"> <property name="tokens" value="NUM_DOUBLE, NUM_FLOAT"/> <property name="ignoreNumbers" value="0, 0.5, 1"/> <property name="ignoreFieldDeclaration" value="true"/> <property name="ignoreAnnotation" value="true"/> </module> </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> <module name="MagicNumber"> <property name="constantWaiverParentToken" value="ASSIGN,ARRAY_INIT,EXPR, UNARY_PLUS, UNARY_MINUS, TYPECAST, ELIST, DIV, PLUS "/> </module> </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" id="MagicNumber_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" id="MagicNumber_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" id="MagicNumber_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="MagicNumber_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="MissingCtor"> <subsection name="Description" id="MissingCtor_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" id="MissingCtor_Examples"> <p> To configure the check: </p> <source> <module name="MissingCtor"/> </source> </subsection> <subsection name="Example of Usage" id="MissingCtor_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" id="MissingCtor_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" id="MissingCtor_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="MissingCtor_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="MissingSwitchDefault"> <subsection name="Description" id="MissingSwitchDefault_Description"> <p>Since Checkstyle 3.1</p> <p> Checks that switch statement has a "default" 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" id="MissingSwitchDefault_Examples"> <p> To configure the check: </p> <source> <module name="MissingSwitchDefault"/> </source> </subsection> <subsection name="Example of Usage" id="MissingSwitchDefault_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" id="MissingSwitchDefault_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" id="MissingSwitchDefault_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="MissingSwitchDefault_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="ModifiedControlVariable"> <subsection name="Description" id="ModifiedControlVariable_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 < 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 < 10;) { i++; } </source> </subsection> <subsection name="Properties" id="ModifiedControlVariable_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" id="ModifiedControlVariable_Examples"> <p> To configure the check: </p> <source> <module name="ModifiedControlVariable"/> </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> <module name="ModifiedControlVariable"> <property name="skipEnhancedForLoopVariable" value="true"/> </module> </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" id="ModifiedControlVariable_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" id="ModifiedControlVariable_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" id="ModifiedControlVariable_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="ModifiedControlVariable_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="MultipleStringLiterals"> <subsection name="Description" id="MultipleStringLiterals_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" id="MultipleStringLiterals_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> </td> <td>4.4</td> </tr> </table> </subsection> <subsection name="Examples" id="MultipleStringLiterals_Examples"> <p> To configure the check: </p> <source> <module name="MultipleStringLiterals"/> </source> <p> To configure the check so that it allows two occurrences of each string: </p> <source> <module name="MultipleStringLiterals"> <property name="allowedDuplicates" value="2"/> </module> </source> <p> To configure the check so that it ignores ", " and empty strings: </p> <source> <module name="MultipleStringLiterals"> <property name="ignoreStringsRegexp" value='^(("")|(", "))$'/> </module> </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> <module name="MultipleStringLiterals"> <property name="ignoreOccurrenceContext" value=""/> </module> </source> </subsection> <subsection name="Example of Usage" id="MultipleStringLiterals_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" id="MultipleStringLiterals_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" id="MultipleStringLiterals_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="MultipleStringLiterals_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="MultipleVariableDeclarations"> <subsection name="Description" id="MultipleVariableDeclarations_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="https://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" id="MultipleVariableDeclarations_Examples"> <p> To configure the check: </p> <source> <module name="MultipleVariableDeclarations"/> </source> </subsection> <subsection name="Example of Usage" id="MultipleVariableDeclarations_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" id="MultipleVariableDeclarations_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" id="MultipleVariableDeclarations_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="MultipleVariableDeclarations_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="NestedForDepth"> <subsection name="Description" id="NestedForDepth_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" id="NestedForDepth_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" id="NestedForDepth_Examples"> <p> To configure the check: </p> <source> <module name="NestedForDepth"/> </source> <p> To configure the check to allow nesting depth 3: </p> <source> <module name="NestedForDepth"> <property name="max" value="3"/> </module> </source> </subsection> <subsection name="Example of Usage" id="NestedForDepth_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" id="NestedForDepth_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" id="NestedForDepth_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="NestedForDepth_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="NestedIfDepth"> <subsection name="Description" id="NestedIfDepth_Description"> <p>Since Checkstyle 3.2</p> <p> Restricts nested if-else blocks to a specified depth (default = 1). </p> </subsection> <subsection name="Properties" id="NestedIfDepth_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" id="NestedIfDepth_Examples"> <p> To configure the check: </p> <source> <module name="NestedIfDepth"/> </source> <p> To configure the check to allow nesting depth 3: </p> <source> <module name="NestedIfDepth"> <property name="max" value="3"/> </module> </source> </subsection> <subsection name="Example of Usage" id="NestedIfDepth_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" id="NestedIfDepth_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" id="NestedIfDepth_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="NestedIfDepth_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="NestedTryDepth"> <subsection name="Description" id="NestedTryDepth_Description"> <p>Since Checkstyle 3.2</p> <p> Restricts nested try blocks to a specified depth (default = 1). </p> </subsection> <subsection name="Properties" id="NestedTryDepth_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" id="NestedTryDepth_Examples"> <p> To configure the check: </p> <source> <module name="NestedTryDepth"/> </source> <p> To configure the check to allow nesting depth 3: </p> <source> <module name="NestedTryDepth"> <property name="max" value="3"/> </module> </source> </subsection> <subsection name="Example of Usage" id="NestedTryDepth_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" id="NestedTryDepth_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" id="NestedTryDepth_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="NestedTryDepth_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="NoClone"> <subsection name="Description" id="NoClone_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" id="NoClone_Examples"> <p> To configure the check: </p> <source> <module name="NoClone"/> </source> </subsection> <subsection name="Example of Usage" id="NoClone_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" id="NoClone_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" id="NoClone_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="NoClone_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="NoFinalizer"> <subsection name="Description" id="NoFinalizer_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" id="NoFinalizer_Examples"> <p> To configure the check: </p> <source> <module name="NoFinalizer"/> </source> </subsection> <subsection name="Example of Usage" id="NoFinalizer_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" id="NoFinalizer_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" id="NoFinalizer_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="NoFinalizer_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="OneStatementPerLine"> <subsection name="Description" id="OneStatementPerLine_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" id="OneStatementPerLine_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> <module name="OneStatementPerLine"/> </source> </subsection> <subsection name="Example of Usage" id="OneStatementPerLine_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" id="OneStatementPerLine_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" id="OneStatementPerLine_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="OneStatementPerLine_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="OverloadMethodsDeclarationOrder"> <subsection name="Description" id="OverloadMethodsDeclarationOrder_Description"> <p>Since Checkstyle 5.8</p> <p> Checks that overload methods are grouped together. </p> </subsection> <subsection name="Examples" id="OverloadMethodsDeclarationOrder_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> <module name="OverloadMethodsDeclarationOrder"/> </source> </subsection> <subsection name="Example of Usage" id="OverloadMethodsDeclarationOrder_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" id="OverloadMethodsDeclarationOrder_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" id="OverloadMethodsDeclarationOrder_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="OverloadMethodsDeclarationOrder_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="PackageDeclaration"> <subsection name="Description" id="PackageDeclaration_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" id="PackageDeclaration_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" id="PackageDeclaration_Examples"> <p> To configure the check: </p> <source> <module name="PackageDeclaration"/> </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> <module name="PackageDeclaration"> <property name="matchDirectoryStructure" value="false"/> </module> </source> <source> package com.puppycrawl.tools.checkstyle.checks; //No Violation public class AnnotationLocationCheck extends AbstractCheck { //... } </source> </subsection> <subsection name="Example of Usage" id="PackageDeclaration_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" id="PackageDeclaration_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" id="PackageDeclaration_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="PackageDeclaration_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="ParameterAssignment"> <subsection name="Description" id="ParameterAssignment_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" id="ParameterAssignment_Examples"> <p> To configure the check: </p> <source> <module name="ParameterAssignment"/> </source> </subsection> <subsection name="Example of Usage" id="ParameterAssignment_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" id="ParameterAssignment_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" id="ParameterAssignment_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="ParameterAssignment_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="RequireThis"> <subsection name="Description" id="RequireThis_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 "this.varName" or "this.methodName(args)" and that those references don't rely on the default behavior when "this." 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 "this." 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" id="RequireThis_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" id="RequireThis_Examples"> <p> To configure the default check: </p> <source> <module name="RequireThis"/> </source> <p> To configure to check the <code>this</code> qualifier for fields only: </p> <source> <module name="RequireThis"> <property name="checkMethods" value="false"/> </module> </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" id="RequireThis_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" id="RequireThis_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" id="RequireThis_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="RequireThis_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="ReturnCount"> <subsection name="Description" id="ReturnCount_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" id="ReturnCount_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" id="ReturnCount_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> <module name="ReturnCount"> <property name="max" value="3"/> </module> </source> <p> To configure the check so that it doesn't allow any return statements per void method: </p> <source> <module name="ReturnCount"> <property name="maxForVoid" value="0"/> </module> </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> <module name="ReturnCount"> <property name="max" value="2"/> <property name="maxForVoid" value="1"/> </module> </source> <p> To configure the check so that it doesn't allow more than three return statements per method for all methods: </p> <source> <module name="ReturnCount"> <property name="max" value="3"/> <property name="format" value="^$"/> </module> </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> <module name="ReturnCount"> <property name="max" value="0"/> <property name="tokens" value="CTOR_DEF"/> </module> <module name="ReturnCount"> <property name="max" value="1"/> <property name="tokens" value="LAMBDA"/> </module> <module name="ReturnCount"> <property name="max" value="2"/> <property name="tokens" value="METHOD_DEF"/> </module> </source> </subsection> <subsection name="Example of Usage" id="ReturnCount_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" id="ReturnCount_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" id="ReturnCount_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="ReturnCount_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="SimplifyBooleanExpression"> <subsection name="Description" id="SimplifyBooleanExpression_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" id="SimplifyBooleanExpression_Examples"> <p> To configure the check: </p> <source> <module name="SimplifyBooleanExpression"/> </source> </subsection> <subsection name="Example of Usage" id="SimplifyBooleanExpression_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" id="SimplifyBooleanExpression_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" id="SimplifyBooleanExpression_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="SimplifyBooleanExpression_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="SimplifyBooleanReturn"> <subsection name="Description" id="SimplifyBooleanReturn_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" id="SimplifyBooleanReturn_Examples"> <p> To configure the check: </p> <source> <module name="SimplifyBooleanReturn"/> </source> </subsection> <subsection name="Example of Usage" id="SimplifyBooleanReturn_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" id="SimplifyBooleanReturn_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" id="SimplifyBooleanReturn_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="SimplifyBooleanReturn_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="StringLiteralEquality"> <subsection name="Description" id="StringLiteralEquality_Description"> <p>Since Checkstyle 3.2</p> <p> Checks that string literals are not used with <code>==</code> or <code>!=</code>. </p> <p> Rationale: Novice Java programmers often use code like: </p> <source> if (x == "something") </source> <p>when they mean</p> <source> if ("something".equals(x)) </source> </subsection> <subsection name="Examples" id="StringLiteralEquality_Examples"> <p> To configure the check: </p> <source> <module name="StringLiteralEquality"/> </source> </subsection> <subsection name="Example of Usage" id="StringLiteralEquality_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" id="StringLiteralEquality_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" id="StringLiteralEquality_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="StringLiteralEquality_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="SuperClone"> <subsection name="Description" id="SuperClone_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" id="SuperClone_Examples"> <p> To configure the check: </p> <source> <module name="SuperClone"/> </source> </subsection> <subsection name="Example of Usage" id="SuperClone_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" id="SuperClone_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" id="SuperClone_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="SuperClone_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="SuperFinalize"> <subsection name="Description" id="SuperFinalize_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="https://www.oracle.com/technetwork/java/javamail/finalization-137655.html"> Use Finalization Only When You Must</a>. </p> </subsection> <subsection name="Examples" id="SuperFinalize_Examples"> <p> To configure the check: </p> <source> <module name="SuperFinalize"/> </source> </subsection> <subsection name="Example of Usage" id="SuperFinalize_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" id="SuperFinalize_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" id="SuperFinalize_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="SuperFinalize_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="UnnecessaryParentheses"> <subsection name="Description" id="UnnecessaryParentheses_Description"> <p>Since Checkstyle 3.4</p> <p> Checks for the use of unnecessary parentheses. </p> </subsection> <subsection name="Properties" id="UnnecessaryParentheses_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" id="UnnecessaryParentheses_Examples"> <p> To configure the check: </p> <source> <module name="UnnecessaryParentheses"/> </source> </subsection> <subsection name="Example of Usage" id="UnnecessaryParentheses_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" id="UnnecessaryParentheses_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" id="UnnecessaryParentheses_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="UnnecessaryParentheses_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> <section name="VariableDeclarationUsageDistance"> <subsection name="Description" id="VariableDeclarationUsageDistance_Description"> <p>Since Checkstyle 5.8</p> <p> Checks the distance between declaration of variable and its first usage. </p> </subsection> <subsection name="Properties" id="VariableDeclarationUsageDistance_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" id="VariableDeclarationUsageDistance_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> <module name="VariableDeclarationUsageDistance"/> </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> <module name="VariableDeclarationUsageDistance"> <property name="allowedDistance" value="4"/> <property name="ignoreVariablePattern" value="^temp.*"/> <property name="validateBetweenScopes" value="true"/> <property name="ignoreFinal" value="false"/> </module> </source> </subsection> <subsection name="Notes" id="VariableDeclarationUsageDistance_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 < 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" id="VariableDeclarationUsageDistance_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" id="VariableDeclarationUsageDistance_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" id="VariableDeclarationUsageDistance_Package"> <p> com.puppycrawl.tools.checkstyle.checks.coding </p> </subsection> <subsection name="Parent Module" id="VariableDeclarationUsageDistance_Parent_Module"> <p> <a href="config.html#TreeWalker">TreeWalker</a> </p> </subsection> </section> </body> </document>
© 2015 - 2025 Weber Informatics LLC | Privacy Policy