diff options
10 files changed, 3069 insertions, 5983 deletions
diff --git a/plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/rules.xml b/plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/rules.xml index 5f7494d662d..4f9030f57f5 100644 --- a/plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/rules.xml +++ b/plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/rules.xml @@ -1,4 +1,4 @@ - <rules> +<rules> <!-- Checkstyle 5.0 --> <rule> @@ -15,1689 +15,1429 @@ </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.header.RegexpHeaderCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.header.RegexpHeaderCheck"> + <priority>MAJOR</priority> <name><![CDATA[Regexp Header]]></name> <configKey><![CDATA[Checker/RegexpHeader]]></configKey> - <description><![CDATA[<p>Checks the header of a source file against a header that contains a regular expression for each line of the source header.</p> - <p>Rationale: In some projects checking against a fixed header is not sufficient, e.g. the header might require a copyright line where the year information is not static. For example, consider the following header:</p> -<pre> - line 1: ^/{71}$ - line 2: ^// checkstyle:$ - line 3: ^// Checks Java source code for adherence to a set of rules\.$ - line 4: ^// Copyright \(C\) \d\d\d\d Oliver Burn$ - line 5: ^// Last modification by \$Author.*\$$ - line 6: ^/{71}$ - line 7: - line 8: ^package - line 9: - line 10: ^import - line 11: - line 12: ^/\*\* - line 13: ^ \*([^/]|$) - line 14: ^ \*/ -</pre> -<p>Lines 1 and 6 demonstrate a more compact notation for 71 '/' characters. Line 4 enforces that the copyright notice includes a four digit year. Line 5 is an example how to enforce revision control keywords in a file header. Lines 12-14 is a template for javadoc (line 13 is so complicated to remove conflict with and of javadoc comment).</p> -<p>Different programming languages have different comment syntax rules, but all of them start a comment with a non-word character. Hence you can often use the non-word character class to abstract away the concrete comment syntax and allow checking the header for different languages with a single header definition. For example, consider the following header specification (note that this is not the full Apache license header):</p> -<pre> - line 1: ^#! - line 2: ^<\?xml.*>$ - line 3: ^\W*$ - line 4: ^\W*Copyright 2006 The Apache Software Foundation or its licensors, as applicable\.$ - line 5: ^\W*Licensed under the Apache License, Version 2\.0 \(the "License"\);$ - line 6: ^\W*$ -</pre> -<p>Lines 1 and 2 leave room for technical header lines, e.g. the "#!/bin/sh" line in Unix shell scripts, or the xml file header of XML files. Set the multiline property to "1, 2" so these lines can be ignored for file types where they do no apply. Lines 3 through 6 define the actual header content. Note how lines 2, 4 and 5 use escapes for characters that have special regexp semantics.</p>]]></description> + <param key="header" type="s"> - <description><![CDATA[the required header specified inline. Individual header lines must be separated by the string "\n" (even on platforms with a different line separator), and regular expressions must not span multiple lines.]]></description> + </param> <param key="ignoreLines" type="s"> - <description><![CDATA[line numbers to repeat (zero or more times)]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck"> + <priority>MAJOR</priority> <name><![CDATA[Annotation Use Style]]></name> <configKey><![CDATA[Checker/TreeWalker/AnnotationUseStyle]]></configKey> - <description><![CDATA[Controls the style with the usage of annotations.]]></description> + <param key="elementStyle" type="s[expanded,compact,compact_no_array,ignore]"> - <description><![CDATA[Defines the annotation element styles. Default value is compact_no_array.]]></description> + </param> <param key="closingParens" type="s[always,never,ignore]"> - <description><![CDATA[Defines the policy for ending parenthesis. Default is never.]]></description> + </param> <param key="trailingArrayComma" type="s[always,never,ignore]"> - <description><![CDATA[Defines the policy for trailing comma in arrays. Default is never.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.annotation.MissingDeprecatedCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.annotation.MissingDeprecatedCheck"> + <priority>MAJOR</priority> <name><![CDATA[Missing Deprecated]]></name> <configKey><![CDATA[Checker/TreeWalker/MissingDeprecated]]></configKey> - <description> - <![CDATA[Verifies that both the java.lang.Deprecated annotation is present and the @deprecated Javadoc tag is present when either is present.]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.annotation.MissingOverrideCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.annotation.MissingOverrideCheck"> + <priority>MAJOR</priority> <name><![CDATA[Missing Override]]></name> <configKey><![CDATA[Checker/TreeWalker/MissingOverride]]></configKey> - <description> - <![CDATA[Verifies that the java.lang.Override annotation is present when the {@inheritDoc} javadoc tag is present.]]></description> + <param key="javaFiveCompatibility" type="b"> - <description> - <![CDATA[When this property is true this check will only check classes, interfaces, etc. that do not contain the extends or implements keyword or are not anonymous classes. This means it only checks methods overridden from java.lang.Object Java 5 Compatibility mode severely limits this check. It is recommended to only use it on Java 5 source.]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.annotation.PackageAnnotationCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Package Annotation]]></name> <configKey><![CDATA[Checker/TreeWalker/PackageAnnotation]]></configKey> - <description><![CDATA[<p>This check makes sure that all package annotations are in the package-info.java file.</p> -<p>According to the Java JLS 3rd ed.</p> -<p>The JLS does not enforce the placement of package annotations. This placement may vary based on implementation. The JLS does highly recommend that all package annotations are placed in the package-info.java file. See <a href="http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html">Java Language specification, sections 7.4.1.1</a>.</p>]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.annotation.SuppressWarningsCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.annotation.SuppressWarningsCheck"> + <priority>MAJOR</priority> <name><![CDATA[Suppress Warnings]]></name> <configKey><![CDATA[Checker/TreeWalker/SuppressWarnings]]></configKey> - <description> - <![CDATA[<p> This check allows you to specify what warnings that SuppressWarnings is not allowed to suppress. You can also specify a list of TokenTypes that the configured warning(s) cannot be suppressed on.</p> -<p>Limitations: This check does not consider conditionals inside the SuppressWarnings annotation. -For example: @SupressWarnings((false) ? (true) ? "unchecked" : "foo" : "unused") According to the above example, the "unused" warning is being suppressed not the "unchecked" or "foo" warnings. All of these warnings will be considered and matched against regardless of what the conditional evaluates to.</p>]]></description> + <param key="format" type="s"> - <description> - <![CDATA[The warnings property is a regex pattern. Any warning being suppressed matching this pattern will be flagged. Default is ^$|^\s+$]]></description> + </param> <param key="tokens" type="s"> - <description> - <![CDATA[Tokens to check : CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF ENUM_CONSTANT_DEF, PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF, CTOR_DEF. Default value is LASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF, ENUM_CONSTANT_DEF, PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF, CTOR_DEF.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck"> + <priority>MAJOR</priority> <name><![CDATA[Equals Avoid Null]]></name> <configKey><![CDATA[Checker/TreeWalker/EqualsAvoidNull]]></configKey> - <description> - <![CDATA[<p>Checks that any combination of String literals with optional assignment is on the left side of an equals() comparison.</p> -<p>Rationale: Calling the equals() method on String literals will avoid a potential NullPointerException. Also, it is pretty common to see null check right before equals comparisons which is not necessary in the below example.</p> -<p>For example: -<pre> - String nullString = null; - nullString.equals("My_Sweet_String"); -</pre> -</p> - -<p> -should be refactored to: -<pre> - String nullString = null; - "My_Sweet_String".equals(nullString); -</pre> -</p> -<p>Limitations: If the equals method is overridden or a covariant equals method is defined and the implementation is incorrect (where s.equals(t) does not return the same result as t.equals(s)) then rearranging the called on object and parameter may have unexpected results.</p> -<p>Java's Autoboxing feature has an affect on how this check is implemented. Pre Java 5 all IDENT + IDENT object concatenations would not cause a NullPointerException even if null. Those situations could have been included in this check. They would simply act as if they surrounded by String.valueof() which would concatenate the String null.</p> -<p>The following example will cause a NullPointerException as a result of what autoboxing does.</p> -<pre> - Integer i = null, j = null; - String number = "5" - number.equals(i + j); -</pre> -<p>Since, it is difficult to determine what kind of Object is being concatenated all ident concatenation is considered unsafe.</p>]]></description> - </rule> - - -<rule key="com.puppycrawl.tools.checkstyle.checks.coding.NoCloneCheck" > -<priority>MAJOR</priority> + + </rule> + + + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.NoCloneCheck"> + <priority>MAJOR</priority> <name><![CDATA[No Clone]]></name> <configKey><![CDATA[Checker/TreeWalker/NoClone]]></configKey> - <description><![CDATA[<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 do not work it all situations. Consequently, it is difficult to override correctly. Below are some of the rules/reasons why the clone method should be avoided. -<ul> - <li>Classes supporting the clone method should implement the Cloneable interface but the Cloneable interface does not include the clone method. As a result, it doesn't enforce the method override.</li> - <li>The Cloneable interface forces the Object's clone method to work correctly. Without implementing it, the Object's clone method will throw a CloneNotSupportedException.</li> - <li>Non-final classes must return the object returned from a call to super.clone().</li> - <li>Final classes can use a constructor to create a clone which is different from non-final classes.</li> - <li>If a super class implements the clone method incorrectly all subclasses calling super.clone() are doomed to failure.</li> - <li>If a class has references to mutable objects then those object references must be replaced with copies in the clone method after calling super.clone().</li> - <li>The clone method does not work correctly with final mutable object references because final references cannot be reassigned.</li> - <li>If a super class overrides the clone method then all subclasses must provide a correct clone implementation.</li> -</ul></p> -<p>Two alternatives to the clone method, in some cases, is a copy constructor or a static factory method to return copies of an object. Both of these approaches are simpler and do not conflict with final fields. The do not force the calling client to handle a CloneNotSuportException. They also are typed therefore no casting is necessary. Finally, they are more flexible since they can take interface types rather than concrete classes.</p> - -<p>Sometimes a copy constructor or static factory is not an acceptable alternative to the clone method. The example below highlights the limitation of a copy constructor (or static factory). Assume Square is a subclass for Shape.</p> -<p> -<pre> - Shape s1 = new Square(); - System.out.println(s1 instanceof Square); //true -</pre></p> -<p>...assume at this point the code knows nothing of s1 being a Square that's the beauty of polymorphism but the code wants to copy the Square which is declared as a Shape, its super type...</p> -<p> -<pre> - Shape s2 = new Shape(s1); //using the copy constructor - System.out.println(s2 instanceof Square); //false -</pre></p> - -<p>The working solution (without knowing about all subclasses and doing many casts) is to do the following (assuming correct clone implementation).<br/> -<pre> - Shape s2 = s1.clone(); - System.out.println(s2 instanceof Square); //true -</pre></p> - -<p>Just keep in mind if this type of polymorphic cloning is required then a properly implemented clone method may be the best choice.</p> - -<p>Much of this information was taken from Effective Java: Programming Language Guide First Edition by Joshua Bloch pages 45-52. Give Bloch credit for writing an excellent book.</p> - -<p>This check is almost exactly the same as the "No Finalizer Check".</p>]]></description> - </rule> - - - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.NoFinalizerCheck" > -<priority>MAJOR</priority> + + </rule> + + + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.NoFinalizerCheck"> + <priority>MAJOR</priority> <name><![CDATA[No Finalizer]]></name> <configKey><![CDATA[Checker/TreeWalker/NoFinalizer]]></configKey> - <description><![CDATA[<p>Verifies there are no finalize() methods defined in a class.</p>]]></description> + </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.imports.AvoidStaticImportCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Avoid Static Import]]></name> <configKey><![CDATA[Checker/TreeWalker/AvoidStaticImport]]></configKey> - <description><![CDATA[<p> Checks that there are no static import statements. Rationale: Importing static members can lead to naming conflicts between class' members. It may lead to poor code readability since it may no longer be clear what class a member resides in (without looking at the import statement).</p>]]></description> + <param key="excludes" type="s{}"> - <description> - <![CDATA[Allows for certain classes via a star notation to be excluded such as java.lang.Math.* or specific static members to be excluded like java.lang.System.out for a variable or java.lang.Math.random for a method. -If you exclude a starred import on a class this automatically excludes each member individually. -For example: Excluding java.lang.Math.*. will allow the import of each static member in the Math class individually like java.lang.Math.PI.]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Javadoc Package]]></name> <configKey><![CDATA[Checker/JavadocPackage]]></configKey> - <description><![CDATA[<p>Checks that each Java package has a Javadoc file used for commenting. By default it only allows a package-info.java file, but can be configured to allow a package.html file. An error will be reported if both files exist as this is not allowed by the Javadoc tool.</p>]]></description> + <param key="allowLegacy" type="b"> - <description> - <![CDATA[If set then allow the use of a package.html file.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpMultilineCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpMultilineCheck"> + <priority>MAJOR</priority> <name><![CDATA[Regexp Multiline]]></name> <configKey><![CDATA[Checker/RegexpMultiline]]></configKey> <cardinality>MULTIPLE</cardinality> - <description><![CDATA[<p>A check for detecting that matches across multiple lines. Rationale: This check can be used to when the regular expression can be span multiple lines.</p>]]></description> + <param key="format" type="s"> - <description><![CDATA[illegal pattern. Default value is ^$ (empty).]]></description> + </param> <param key="message" type="s"> - <description><![CDATA[message which is used to notify about violations, if empty then default(hard-coded) message is used. Default value is "" (empty).]]></description> + </param> <param key="ignoreCase" type="b"> - <description><![CDATA[Controls whether to ignore case when searching. Default value is false.]]></description> + </param> <param key="minimum" type="i"> - <description><![CDATA[The minimum number of matches required in each file. Default value is 0.]]></description> + </param> <param key="maximum" type="i"> - <description><![CDATA[The maximum number of matches required in each file. Default value is 0.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck"> + <priority>MAJOR</priority> <name><![CDATA[Regexp Singleline]]></name> <configKey><![CDATA[Checker/RegexpSingleline]]></configKey> - <description><![CDATA[<p> A check for detecting single lines that match a supplied regular expression. Works with any file type. Rationale: This check can be used to prototype checks and to find common bad practice such as calling ex.printStacktrace(), System.out.println(), System.exit(), etc.</p>]]></description> + <cardinality>MULTIPLE</cardinality> <param key="format" type="s"> - <description><![CDATA[illegal pattern. Default value is ^$ (empty).]]></description> + </param> <param key="message" type="s"> - <description><![CDATA[message which is used to notify about violations, if empty then default(hard-coded) message is used. Default value is "" (empty).]]></description> + </param> <param key="ignoreCase" type="b"> - <description><![CDATA[Controls whether to ignore case when searching. Default value is false.]]></description> + </param> <param key="minimum" type="i"> - <description><![CDATA[The minimum number of matches required in each file. Default value is 0.]]></description> + </param> <param key="maximum" type="i"> - <description><![CDATA[The maximum number of matches required in each file. Default value is 0.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck"> + <priority>MAJOR</priority> <name><![CDATA[Regexp Singleline Java]]></name> <configKey><![CDATA[Checker/TreeWalker/RegexpSinglelineJava]]></configKey> - <description><![CDATA[<p>This class is variation on RegexpSingleline for detecting single lines that match a supplied regular expression in Java files. It supports suppressing matches in Java comments.</p>]]></description> + <cardinality>MULTIPLE</cardinality> <param key="format" type="s"> - <description><![CDATA[illegal pattern. Default value is ^$ (empty).]]></description> + </param> <param key="message" type="s"> - <description><![CDATA[message which is used to notify about violations, if empty then default(hard-coded) message is used. Default value is "" (empty).]]></description> + </param> <param key="ignoreCase" type="b"> - <description><![CDATA[Controls whether to ignore case when searching. Default value is false.]]></description> + </param> <param key="minimum" type="i"> - <description><![CDATA[The minimum number of matches required in each file. Default value is 0.]]></description> + </param> <param key="maximum" type="i"> - <description><![CDATA[The maximum number of matches required in each file. Default value is 0.]]></description> + </param> <param key="ignoreComments" type="b"> - <description><![CDATA[Controls whether to ignore text in comments when searching. Default value is false.]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.sizes.OuterTypeNumberCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Outer Type Number]]></name> <configKey><![CDATA[Checker/TreeWalker/OuterTypeNumber]]></configKey> - <description><![CDATA[<p> Checks for the number of types declared at the outer (or root) level in a file. Rationale: It is considered good practice to only define one outer type per file.</p>]]></description> + <param key="max" type="i"> - <description><![CDATA[maximum allowable number of outer types. Default is 1.]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[File Tab Character]]></name> <configKey><![CDATA[Checker/FileTabCharacter]]></configKey> - <description><![CDATA[<p>Checks that there are no tab characters ('\t') in the source code. Rationale: -<ul> - <li>Developers should not need to configure the tab width of their text editors in order to be able to read source code.</li> - <li>From the Apache jakarta coding standards: In a distributed development environment, when the commit messages get sent to a mailing list, they are almost impossible to read if you use tabs.</li> -</ul></p>]]></description> + <param key="eachLine" type="b"> - <description><![CDATA[whether to report on each line containing a tab, or just the first instance. Default is false.]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.whitespace.GenericWhitespaceCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Generic Whitespace]]></name> <configKey><![CDATA[Checker/TreeWalker/GenericWhitespace]]></configKey> - <description><![CDATA[<p>Checks that the whitespace around the Generic tokens < and > is correct to the typical convention. The convention is not configurable.</p> -<p> -For example the following is legal: -</p> -<pre> - List<Integer> x = new ArrayList<Integer>(); - List<List<Integer>> y = new ArrayList<List<Integer>>(); -</pre> -<p> -But the following example is not: -</p> -<pre> - List < Integer > x = new ArrayList < Integer > (); - List < List < Integer > > y = new ArrayList < List < Integer > > (); -</pre>]]></description> + </rule> <!-- Checkstyle 4.4 and less --> - <rule key="com.puppycrawl.tools.checkstyle.checks.metrics.JavaNCSSCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.metrics.JavaNCSSCheck"> + <priority>MAJOR</priority> <name><![CDATA[JavaNCSS]]></name> <configKey><![CDATA[Checker/TreeWalker/JavaNCSS]]></configKey> - <description><![CDATA[ Determines complexity of methods, classes and files by counting the Non Commenting Source Statements (NCSS). This check adheres to the specification for the JavaNCSS-Tool written by Chr. Clemens Lee. -Rougly said the NCSS metric is calculated by counting the source lines which are not comments, (nearly) equivalent to counting the semicolons and opening curly braces. -The NCSS for a class is summarized from the NCSS of all its methods, the NCSS of its nested classes and the number of member variable declarations. -The NCSS for a file is summarized from the ncss of all its top level classes, the number of imports and the package declaration. -<br> -Rationale: Too large methods and classes are hard to read and costly to maintain. A large NCSS number often means that a method or class has too many responsabilities and/or functionalities which should be decomposed into smaller units.]]></description> + <param key="methodMaximum" type="i"> - <description> - <![CDATA[the maximum allowed number of non commenting lines in a method. Default is 50.]]></description> + </param> <param key="classMaximum" type="i"> - <description> - <![CDATA[the maximum allowed number of non commenting lines in a class. Default is 1500.]]></description> + </param> <param key="fileMaximum" type="i"> - <description> - <![CDATA[the maximum allowed number of non commenting lines in a file including all top level and nested classes. Default is 2000.]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.imports.RedundantImportCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Redundant import]]></name> <configKey><![CDATA[Checker/TreeWalker/RedundantImport]]></configKey> - <description><![CDATA[Checks for redundant import statements. An import statement is considered redundant if: -<ul> - <li>It is a duplicate of another import. This is, when a class is imported more than once.</li> - <li>The class imported is from the java.lang package, e.g. importing java.lang.String.</li> - <li>The class imported is from the same package.</li></ul> -]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.naming.AbstractClassNameCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.naming.AbstractClassNameCheck"> + <priority>MAJOR</priority> <name><![CDATA[Abstract Class Name]]></name> <configKey><![CDATA[Checker/TreeWalker/AbstractClassName]]></configKey> - <description> - <![CDATA[Checks that abstract class names conform to the specified format]]></description> + <param key="format" type="r"> <defaultValue>^Abstract.*$|^.*Factory$</defaultValue> </param> <!-- Not supported yet <param key="ignoreModifier" type="b"> - <description>Controls whether to ignore checking for the abstract modifier on classes that match the name.</description> + <defaultValue>false</defaultValue> </param> <param key="ignoreName" type="b"> - <description>Controls whether to ignore checking the name. Realistically only useful if using the check to identify that match name and do not have the abstract modifier name.</description> + <defaultValue>false</defaultValue> </param> --> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.sizes.AnonInnerLengthCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.sizes.AnonInnerLengthCheck"> + <priority>MAJOR</priority> <name><![CDATA[Anon Inner Length]]></name> <configKey><![CDATA[Checker/TreeWalker/AnonInnerLength]]></configKey> - <description><![CDATA[Checks for long anonymous inner classes.]]></description> + <param key="max" type="i"> - <description><![CDATA[maximum allowable number of lines. Default is 20.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.ArrayTrailingCommaCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.ArrayTrailingCommaCheck"> + <priority>MAJOR</priority> <name><![CDATA[Array Trailing Comma]]></name> <configKey><![CDATA[Checker/TreeWalker/ArrayTrailingComma]]></configKey> - <description><![CDATA[Checks if array initialization contains optional trailing comma.]]></description> + </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.ArrayTypeStyleCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Array Type Style]]></name> <configKey><![CDATA[Checker/TreeWalker/ArrayTypeStyle]]></configKey> - <description> - <![CDATA[Checks the style of array type definitions. Some like Java-style: public static void main(String[] args) and some like C-style: public static void main(String args[])]]></description> + <param key="javaStyle" type="b"> - <description> - <![CDATA[Controls whether to enforce Java style (true) or C style (false). Default is true.]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.coding.AvoidInlineConditionalsCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Avoid Inline Conditionals]]></name> <configKey><![CDATA[Checker/TreeWalker/AvoidInlineConditionals]]></configKey> - <description><![CDATA[Detects inline conditionals.]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.blocks.AvoidNestedBlocksCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.blocks.AvoidNestedBlocksCheck"> + <priority>MAJOR</priority> <name><![CDATA[Avoid Nested Blocks]]></name> <configKey><![CDATA[Checker/TreeWalker/AvoidNestedBlocks]]></configKey> - <description><![CDATA[Finds nested blocks.]]></description> + <param key="allowInSwitchCase" type="b"> - <description><![CDATA[Allow nested blocks in case statements. Default is false.]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Avoid Star Import]]></name> <configKey><![CDATA[Checker/TreeWalker/AvoidStarImport]]></configKey> - <description><![CDATA[Check that finds import statements that use the * notation.]]></description> + <param key="excludes" type="s{}"> - <description> - <![CDATA[packages where star imports are allowed. Note that this property is not recursive, subpackages of excluded packages are not automatically excluded.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.metrics.BooleanExpressionComplexityCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.metrics.BooleanExpressionComplexityCheck"> + <priority>MAJOR</priority> <name><![CDATA[Boolean Expression Complexity]]></name> <configKey><![CDATA[Checker/TreeWalker/BooleanExpressionComplexity]]></configKey> - <description> - <![CDATA[Restricts nested boolean operators (&&, || and ^) to a specified depth (default = 3).]]></description> + <param key="max" type="i"> - <description> - <![CDATA[the maximum allowed number of boolean operations in one expression. Default is 3.]]></description> + </param> <param key="tokens" type="s[LAND,BAND,LOR,BOR,BXOR]"> - <description><![CDATA[tokens to check. Default is LAND,BAND,LOR,BOR,BXOR.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.metrics.ClassDataAbstractionCouplingCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.metrics.ClassDataAbstractionCouplingCheck"> + <priority>MAJOR</priority> <name><![CDATA[Class Data Abstraction Coupling]]></name> <configKey><![CDATA[Checker/TreeWalker/ClassDataAbstractionCoupling]]></configKey> - <description> - <![CDATA[This metric measures the number of instantiations of other classes within the given class.]]></description> + <param key="max" type="i"> - <description><![CDATA[the maximum threshold allowed. Default is 7.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.metrics.ClassFanOutComplexityCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.metrics.ClassFanOutComplexityCheck"> + <priority>MAJOR</priority> <name><![CDATA[Class Fan Out Complexity]]></name> <configKey><![CDATA[Checker/TreeWalker/ClassFanOutComplexity]]></configKey> - <description><![CDATA[The number of other classes a given class relies on.]]></description> + <param key="max" type="i"> - <description><![CDATA[the maximum threshold allowed. Default is 20.]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Constant Name]]></name> <configKey><![CDATA[Checker/TreeWalker/ConstantName]]></configKey> <cardinality>MULTIPLE</cardinality> - <description> - <![CDATA[Checks that constant names conform to the specified format]]></description> + <param key="format" type="r"> <defaultValue>^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$</defaultValue> </param> <param key="applyToPublic" type="b"> - <description>Controls whether to apply the check to public member</description> + <defaultValue>true</defaultValue> </param> <param key="applyToProtected" type="b"> - <description>Controls whether to apply the check to protected member</description> + <defaultValue>true</defaultValue> </param> <param key="applyToPackage" type="b"> - <description>Controls whether to apply the check to package-private member</description> <defaultValue>true</defaultValue> </param> <param key="applyToPrivate" type="b"> - <description>Controls whether to apply the check to private member</description> + <defaultValue>true</defaultValue> </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.coding.CovariantEqualsCheck"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Covariant Equals]]></name> <configKey><![CDATA[Checker/TreeWalker/CovariantEquals]]></configKey> - <description> - <![CDATA[Checks that if a class defines a covariant method equals, then it defines method equals(java.lang.Object).]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.metrics.CyclomaticComplexityCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.metrics.CyclomaticComplexityCheck"> + <priority>MAJOR</priority> <name><![CDATA[Cyclomatic Complexity]]></name> <configKey><![CDATA[Checker/TreeWalker/CyclomaticComplexity]]></configKey> - <description> - <![CDATA[Checks cyclomatic complexity of methods against a specified limit. The complexity is measured by the number of if, while, do, for, ?:, catch, switch, case statements, and operators && and || (plus one) in the body of a constructor, method, static initializer, or instance initializer. It is a measure of the minimum number of possible paths through the source and therefore the number of required tests. Generally 1-4 is considered good, 5-7 ok, 8-10 consider re-factoring, and 11+ re-factor now !]]></description> + <param key="max" type="i"> - <description><![CDATA[the maximum threshold allowed. Default is 10.]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.coding.DeclarationOrderCheck"> -<priority>INFO</priority> + <priority>INFO</priority> <name><![CDATA[Declaration Order]]></name> <configKey><![CDATA[Checker/TreeWalker/DeclarationOrder]]></configKey> - <description> - <![CDATA[Checks that the parts of a class or interface declaration appear in the order suggested by the Code Convention for the Java Programming Language : <ul><li>Class (static) variables. First the public class variables, then the protected, then package level (no access modifier), and then the private.</li><li>Instance variables. First the public class variables, then the protected, then package level (no access modifier), and then the private.</li><li>Constructors</li><li>Methods</li></ul>]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.DefaultComesLastCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.DefaultComesLastCheck"> + <priority>MAJOR</priority> <name><![CDATA[Default Comes Last]]></name> <configKey><![CDATA[Checker/TreeWalker/DefaultComesLast]]></configKey> - <description><![CDATA[Check that the default is after all the cases in a switch statement.]]></description> + </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.design.DesignForExtensionCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Design For Extension]]></name> <configKey><![CDATA[Checker/TreeWalker/DesignForExtension]]></configKey> - <description><![CDATA[Checks that classes are designed for inheritance.]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.DoubleCheckedLockingCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.DoubleCheckedLockingCheck"> + <priority>MAJOR</priority> <name><![CDATA[Double Checked Locking]]></name> <configKey><![CDATA[Checker/TreeWalker/DoubleCheckedLocking]]></configKey> - <description> - <![CDATA[Detect the double-checked locking idiom, a technique that tries to avoid synchronization overhead but is incorrect because of subtle artifacts of the java memory model.]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.blocks.EmptyBlockCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.blocks.EmptyBlockCheck"> + <priority>MAJOR</priority> <name><![CDATA[Empty Block]]></name> <configKey><![CDATA[Checker/TreeWalker/EmptyBlock]]></configKey> - <description><![CDATA[Checks for empty blocks.]]></description> + <param key="option" type="s[text,stmt]"> - <description><![CDATA[policy on block contents]]></description> + </param> <param key="tokens" type="s[LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_IF,LITERAL_FOR,LITERAL_TRY,LITERAL_WHILE,INSTANCE_INIT,STATIC_INIT]"> - <description><![CDATA[blocks to check]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyForInitializerPadCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Empty For Initializer Pad]]></name> <configKey><![CDATA[Checker/TreeWalker/EmptyForInitializerPad]]></configKey> - <description> - <![CDATA[Checks the padding of an empty for initializer; that is whether a space is required at an empty for initializer, or such spaces are forbidden. Example : <code>for ( ; i < j; i++, j--)</code>]]></description> + <param key="option" type="s[nospace,space]"> - <description><![CDATA[policy on how to pad an empty for iterator]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyForIteratorPadCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Empty For Iterator Pad]]></name> <configKey><![CDATA[Checker/TreeWalker/EmptyForIteratorPad]]></configKey> - <description> - <![CDATA[Checks the padding of an empty for iterator; that is whether a space is required at an empty for iterator, or such spaces are forbidden. Example : <code>for (Iterator foo = very.long.line.iterator(); foo.hasNext(); )</code>]]></description> + <param key="option" type="s[nospace,space]"> - <description><![CDATA[policy on how to pad an empty for iterator]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.coding.EmptyStatementCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Empty Statement]]></name> <configKey><![CDATA[Checker/TreeWalker/EmptyStatement]]></configKey> - <description><![CDATA[Detects empty statements (standalone ';').]]></description> + </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.coding.EqualsHashCodeCheck"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Equals Hash Code]]></name> <configKey><![CDATA[Checker/TreeWalker/EqualsHashCode]]></configKey> - <description><![CDATA[Checks that classes that override equals() also override hashCode().]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.sizes.ExecutableStatementCountCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.sizes.ExecutableStatementCountCheck"> + <priority>MAJOR</priority> <name><![CDATA[Executable Statement Count]]></name> <configKey><![CDATA[Checker/TreeWalker/ExecutableStatementCount]]></configKey> - <description> - <![CDATA[Restricts the number of executable statements to a specified limit (default = 30).]]></description> + <param key="max" type="i"> - <description><![CDATA[the maximum threshold allowed. Default is 30.]]></description> + </param> <param key="tokens" type="s[CTOR_DEF,METHOD_DEF,INSTANCE_INIT,STATIC_INIT]"> - <description><![CDATA[members to check]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.ExplicitInitializationCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.ExplicitInitializationCheck"> + <priority>MAJOR</priority> <name><![CDATA[Explicit Initialization]]></name> <configKey><![CDATA[Checker/TreeWalker/ExplicitInitialization]]></configKey> - <description> - <![CDATA[Checks if any class or object member explicitly initialized to default for its type value (null for object references, zero for numeric types and char and false for boolean.]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.FallThroughCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.FallThroughCheck"> + <priority>MAJOR</priority> <name><![CDATA[Fall Through]]></name> <configKey><![CDATA[Checker/TreeWalker/FallThrough]]></configKey> - <description> - <![CDATA[Checks for fall through in switch statements Finds locations where a case contains Java code - but lacks a break, return, throw or continue statement.]]></description> + <param key="checkLastCaseGroup" type="b"> - <description><![CDATA[Whether we need to check last case group or not. Default is false.]]></description> + </param> <param key="reliefPattern" type="r"> - <description> - <![CDATA[Regulare expression to match the relief comment that supresses the warning about a fall through.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.sizes.FileLengthCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.sizes.FileLengthCheck"> + <priority>MAJOR</priority> <name><![CDATA[File Length]]></name> <configKey><![CDATA[Checker/FileLength]]></configKey> - <description><![CDATA[<p>Checks for long source files.</p> - <p>Rationale: If a source file becomes very long it is hard to understand. Therefore long classes should usually be refactored into several individual classes that focus on a specific task.</p>]]></description> + <param key="max" type="i"> - <description><![CDATA[maximum allowable number of lines. Default is 2000.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.design.FinalClassCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.design.FinalClassCheck"> + <priority>MAJOR</priority> <name><![CDATA[Final Class]]></name> <configKey><![CDATA[Checker/TreeWalker/FinalClass]]></configKey> - <description><![CDATA[Checks that class which has only private constructors is declared as final.]]></description> + </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.coding.FinalLocalVariableCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Final Local Variable]]></name> <configKey><![CDATA[Checker/TreeWalker/FinalLocalVariable]]></configKey> - <description> - <![CDATA[Ensures that local variables that never get their values changed, must be declared final.]]></description> + <param key="tokens" type="s[PARAMETER_DEF,VARIABLE_DEF]"> - <description><![CDATA[tokens to check]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.FinalParametersCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Final Parameters]]></name> <configKey><![CDATA[Checker/TreeWalker/FinalParameters]]></configKey> - <description><![CDATA[Check that method/constructor/catch/foreach parameters are final.]]></description> + <param key="tokens" type="s[METHOD_DEF,CTOR_DEF,LITERAL_CATCH]"> - <description><![CDATA[blocks to check]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheck"> + <priority>MAJOR</priority> <name><![CDATA[Hidden Field]]></name> <configKey><![CDATA[Checker/TreeWalker/HiddenField]]></configKey> - <description> - <![CDATA[Checks that a local variable or a parameter does not shadow a field that is defined in the same class.]]></description> + <param key="tokens" type="s[PARAMETER_DEF,VARIABLE_DEF]"> - <description><![CDATA[tokens to check]]></description> + </param> <param key="ignoreFormat" type="r"> - <description><![CDATA[pattern for names to ignore]]></description> + </param> <param key="ignoreConstructorParameter" type="b"> - <description><![CDATA[Controls whether to ignore constructor parameters. Default is false.]]></description> + </param> <param key="ignoreSetter" type="b"> - <description> - <![CDATA[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 void. Default is false.]]></description> + </param> <param key="ignoreAbstractMethods" type="b"> - <description> - <![CDATA[Controls whether to ignore parameters of abstract methods. Default is false.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck"> + <priority>MAJOR</priority> <name><![CDATA[Hide Utility Class Constructor]]></name> <configKey><![CDATA[Checker/TreeWalker/HideUtilityClassConstructor]]></configKey> - <description> - <![CDATA[Make sure that utility classes (classes that contain only static methods) do not have a public constructor.]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.IllegalCatchCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.IllegalCatchCheck"> + <priority>MAJOR</priority> <name><![CDATA[Illegal Catch]]></name> <configKey><![CDATA[Checker/TreeWalker/IllegalCatch]]></configKey> - <description> - <![CDATA[Catching java.lang.Exception, java.lang.Error or java.lang.RuntimeException is almost never acceptable.]]></description> + <param key="illegalClassNames" type="s{}"> - <description><![CDATA[exception class names to reject]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck"> + <priority>MAJOR</priority> <name><![CDATA[Illegal Import]]></name> <configKey><![CDATA[Checker/TreeWalker/IllegalImport]]></configKey> - <description><![CDATA[Checks for imports from a set of illegal packages, like sun.*]]></description> + <param key="illegalPkgs" type="s{}"> - <description><![CDATA[packages to reject]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.IllegalInstantiationCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.IllegalInstantiationCheck"> + <priority>MAJOR</priority> <name><![CDATA[Illegal Instantiation]]></name> <configKey><![CDATA[Checker/TreeWalker/IllegalInstantiation]]></configKey> - <description> - <![CDATA[Checks for illegal instantiations where a factory method is preferred. Depending on the project, for some classes it might be preferable to create instances through factory methods rather than calling the constructor. A simple example is the <code>java.lang.Boolean</code> class. In order to save memory and CPU cycles, it is preferable to use the predefined constants TRUE and FALSE. Constructor invocations should be replaced by calls to <code>Boolean.valueOf()</code>. 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.]]></description> + <param key="classes" type="s{}"> - <description><![CDATA[classes that should not be instantiated]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.IllegalThrowsCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.IllegalThrowsCheck"> + <priority>MAJOR</priority> <name><![CDATA[Illegal Throws]]></name> <configKey><![CDATA[Checker/TreeWalker/IllegalThrows]]></configKey> - <description> - <![CDATA[Throwing java.lang.Error or java.lang.RuntimeException is almost never acceptable.]]></description> + <param key="illegalClassNames" type="s{}"> - <description><![CDATA[throw class names to reject]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.IllegalTokenCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.IllegalTokenCheck"> + <priority>MAJOR</priority> <name><![CDATA[Illegal Token]]></name> <configKey><![CDATA[Checker/TreeWalker/IllegalToken]]></configKey> - <description> - <![CDATA[Checks for illegal tokens. Certain language features often lead to hard to maintain code or are non-obvious to novice developers. Other features may be discouraged in certain frameworks, such as not having native methods in EJB components.]]></description> + <param key="tokens" type="s{}"> - <description><![CDATA[tokens to check. Default value is LITERAL_SWITCH, POST_INC, POST_DEC.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.IllegalTokenTextCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.IllegalTokenTextCheck"> + <priority>MAJOR</priority> <name><![CDATA[Illegal Token Text]]></name> <configKey><![CDATA[Checker/TreeWalker/IllegalTokenText]]></configKey> <cardinality>MULTIPLE</cardinality> - <description><![CDATA[Checks for illegal token text.]]></description> + <param key="tokens" type="s{}"> - <description><![CDATA[tokens to check. Default value is empty.]]></description> + </param> <param key="format" type="r"> - <description><![CDATA[illegal pattern]]></description> + </param> <param key="ignoreCase" type="b"> - <description><![CDATA[Controls whether to ignore case when matching. Default is false.]]></description> + </param> <param key="message" type="s"> - <description> - <![CDATA[Message which is used to notify about violations; if empty then the default message is used.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.IllegalTypeCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.IllegalTypeCheck"> + <priority>MAJOR</priority> <name><![CDATA[Illegal Type]]></name> <configKey><![CDATA[Checker/TreeWalker/IllegalType]]></configKey> - <description> - <![CDATA[Checks that particular class are never used as types in variable declarations, return values or parameters.]]></description> + <param key="tokens" type="s[PARAMETER_DEF,VARIABLE_DEF,METHOD_DEF]"> - <description><![CDATA[tokens to check]]></description> + </param> <param key="illegalClassNames" type="s{}"> - <description> - <![CDATA[classes that should not be used as types in variable declarations, return values or parameters.]]></description> + </param> <param key="legalAbstractClassNames" type="s{}"> - <description><![CDATA[abstract classes that may be used as types. ]]></description> + </param> <param key="ignoredMethodNames" type="s{}"> - <description><![CDATA[methods that should not be checked]]></description> + </param> <param key="format" type="r"> - <description><![CDATA[pattern for illegal class name]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Import Order]]></name> <configKey><![CDATA[Checker/TreeWalker/ImportOrder]]></configKey> - <description><![CDATA[ Checks the ordering/grouping of imports. Features are:<ul> - <li>groups imports: ensures that groups of imports come in a specific order (e.g., java. comes first, javax. comes second, then everything else)</li> - <li>adds a separation between groups : ensures that a blank line sit between each group</li> - <li>sorts imports inside each group: ensures that imports within each group are in lexicographic order</li> - <li>sorts according to case: ensures that the comparison between imports is case sensitive</li> - <li>groups static imports: ensures the relative order between regular imports and static imports</li> - </ul> -]]></description> + <param key="option" type="s"> - <description> - <![CDATA[policy on the relative order between regular imports and static imports. Values are top, above, inflow, under, bottom. See examples: http://checkstyle.sourceforge.net/property_types.html#importOrder]]></description> + </param> <param key="groups" type="s{}"> - <description><![CDATA[list of imports groups (every group identified by string it's started)]]></description> + </param> <param key="ordered" type="b"> - <description><![CDATA[whether imports within group should be sorted. Default is true.]]></description> + </param> <param key="separated" type="b"> - <description> - <![CDATA[whether imports groups should be separated by, at least, one blank line. Default is false.]]></description> + </param> <param key="caseSensitive" type="b"> - <description> - <![CDATA[whether string comparision should be case sensitive or not. Default is true.]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Indentation]]></name> <configKey><![CDATA[Checker/TreeWalker/Indentation]]></configKey> - <description><![CDATA[Checks correct indentation of Java Code.]]></description> + <param key="basicOffset" type="i"> - <description><![CDATA[how many spaces to use for new indentation level]]></description> + <defaultValue>4</defaultValue> </param> <param key="braceAdjustment" type="i"> - <description><![CDATA[how far brace should be indented when on next line]]></description> + <defaultValue>0</defaultValue> </param> <param key="caseIndent" type="i"> - <description><![CDATA[how much to indent a case label]]></description> + <defaultValue>4</defaultValue> </param> <param key="tabWidth" type="i"> - <description><![CDATA[number of expanded spaces for a tab character]]></description> + <defaultValue>8</defaultValue> </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.InnerAssignmentCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.InnerAssignmentCheck"> + <priority>MAJOR</priority> <name><![CDATA[Inner Assignment]]></name> <configKey><![CDATA[Checker/TreeWalker/InnerAssignment]]></configKey> - <description> - <![CDATA[Checks for assignments in subexpressions, such as in String s = Integer.toString(i = 2);.]]></description> + <param key="tokens" type="s[ASSIGN,BAND_ASSIGN,BOR_ASSIGN,BSR_ASSIGN,BXOR_ASSIGN,DIV_ASSIGN,MINUS_ASSIGN,MOD_ASSIGN,PLUS_ASSIGN,SL_ASSIGN,SR_ASSIGN,STAR_ASSIGN]"> - <description><![CDATA[assignments to check]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.design.InterfaceIsTypeCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.design.InterfaceIsTypeCheck"> + <priority>MAJOR</priority> <name><![CDATA[Interface Is Type]]></name> <configKey><![CDATA[Checker/TreeWalker/InterfaceIsType]]></configKey> - <description> - <![CDATA[Implements Bloch, Effective Java, Item 17 - Use Interfaces only to define types. According to Bloch, an interface should describe a type. It is therefore inappropriate to define an interface that does not contain any methods but only constants. The Standard class javax.swing.SwingConstants is an example of a class that would be flagged by this check. The check can be configured to also disallow marker interfaces like java.io.Serializable, that do not contain methods or constants at all.]]></description> + <param key="allowMarkerInterfaces" type="b"> - <description> - <![CDATA[Controls whether marker interfaces like Serializable are allowed. Default is true.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck"> + <priority>MAJOR</priority> <name><![CDATA[Javadoc Method]]></name> <configKey><![CDATA[Checker/TreeWalker/JavadocMethod]]></configKey> - <description><![CDATA[Checks the Javadoc of a method or constructor. By default, does not check for unused throws. - To allow documented java.lang.RuntimeExceptions that are not declared, set property allowUndeclaredRTE to true. - The scope to verify is specified using the Scope class and defaults to Scope.PRIVATE. - To verify another scope, set property scope to a different scope. - - <br><br>Error messages about parameters and type parameters for which no param tags are present can be suppressed by defining property allowMissingParamTags. - Error messages about exceptions which are declared to be thrown, but for which no throws tag is present can be suppressed by defining property allowMissingThrowsTags. - Error messages about methods which return non-void but for which no return tag is present can be suppressed by defining property allowMissingReturnTag. - <br><br>Javadoc is not required on a method that is tagged with the @Override annotation. - However under Java 5 it is not possible to mark a method required for an interface (this was corrected under Java 6). - Hence Checkstyle supports using the convention of using a single {@inheritDoc} tag instead of all the other tags. - - <br><br>Note that only inheritable items will allow the {@inheritDoc} tag to be used in place of comments. - Static methods at all visibilities, private non-static methods and constructors are not inheritable.]]></description> <param key="scope" type="s[nothing,public,protected,package,private,anoninner]"> - <description><![CDATA[visibility scope where Javadoc comments are checked]]></description> + </param> <param key="excludeScope" type="s[nothing,public,protected,package,private,anoninner]"> - <description><![CDATA[visibility scope where Javadoc comments are not checked]]></description> + </param> <param key="allowUndeclaredRTE" type="b"> - <description> - <![CDATA[whether to allow documented exceptions that are not declared if they are a subclass of java.lang.RuntimeException. Default is false.]]></description> + </param> <param key="allowThrowsTagsForSubclasses" type="b"> - <description> - <![CDATA[whether to allow documented exceptions that are subclass of one of declared exception. Default is false.]]></description> + </param> <param key="allowMissingParamTags" type="b"> - <description> - <![CDATA[whether to ignore errors when a method has parameters but does not have matching param tags in the javadoc. Default is false.]]></description> + </param> <param key="allowMissingThrowsTags" type="b"> - <description> - <![CDATA[whether to ignore errors when a method declares that it throws exceptions but does have matching throws tags in the javadoc. Default is false.]]></description> + </param> <param key="allowMissingReturnTag" type="b"> - <description> - <![CDATA[whether to ignore errors when a method returns non-void type does have a return tag in the javadoc. Default is false.]]></description> + </param> <param key="allowMissingJavadoc" type="b"> - <description><![CDATA[whether to ignore errors when a method javadoc is missed. Default is false.]]></description> + </param> <param key="allowMissingPropertyJavadoc" type="b"> - <description> - <![CDATA[Whether to allow missing Javadoc on accessor methods for properties (setters and getters). The setter and getter methods must match exactly the structures below. <code> public void setNumber(final int number) { mNumber = number; } public int getNumber() { return mNumber; } public boolean isSomething() { return false; } </code>. Default is false.]]></description> + </param> <param key="tokens" type="s[METHOD_DEF,CTOR_DEF]"> - <description><![CDATA[definitions to check]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck"> + <priority>MAJOR</priority> <name><![CDATA[Javadoc Style]]></name> <configKey><![CDATA[Checker/TreeWalker/JavadocStyle]]></configKey> - <description><![CDATA[Validates Javadoc comments to help ensure they are well formed. The following checks are performed: - <ul> - <li>Ensures the first sentence ends with proper punctuation (That is a period, question mark, or exclamation mark, by default). - Javadoc automatically places the first sentence in the method summary table and index. With out proper punctuation the Javadoc may be malformed. - All items eligible for the {@inheritDoc} tag are exempt from this requirement.</li> - <li>Check text for Javadoc statements that do not have any description. - This includes both completely empty Javadoc, and Javadoc with only tags such as @param and @return.</li> - <li>Check text for incomplete HTML tags. Verifies that HTML tags have corresponding end tags and issues an "Unclosed HTML tag found:" error if not. - An "Extra HTML tag found:" error is issued if an end tag is found without a previous open tag.</li> - <li>Check that a package Javadoc comment is well-formed (as described above) and NOT missing from any package-info.java files.</li> - <li>Check for allowed HTML tags. The list of allowed HTML tags is "a", "abbr", "acronym", "address", "area", "b", - "bdo", "big", "blockquote", "br", "caption", "cite", "code", "colgroup", "del", "div", "dfn", "dl", "em", "fieldset", - "h1" to "h6", "hr", "i", "img", "ins", "kbd", "li", "ol", "p", "pre", "q", "samp", "small", "span", "strong", - "sub", "sup", "table", "tbody", "td", "tfoot", "th", "thread", "tr", "tt", "ul"</li> - </ul>]]></description> + <param key="scope" type="s[nothing,public,protected,package,private,anoninner]"> - <description><![CDATA[visibility scope where Javadoc comments are checked]]></description> + </param> <param key="excludeScope" type="s[nothing,public,protected,package,private,anoninner]"> - <description><![CDATA[visibility scope where Javadoc comments are not checked]]></description> + </param> <param key="checkFirstSentence" type="b"> - <description> - <![CDATA[Whether to check the first sentence for proper end of sentence. Default is true.]]></description> + </param> <param key="checkEmptyJavadoc" type="b"> - <description> - <![CDATA[Whether to check if the Javadoc is missing a describing text. Default is false.]]></description> + </param> <param key="checkHtml" type="b"> - <description><![CDATA[Whether to check for incomplete html tags. Default is true.]]></description> + </param> <param key="tokens" type="s[INTERFACE_DEF,CLASS_DEF,METHOD_DEF,CTOR_DEF,VARIABLE_DEF]"> - <description><![CDATA[definitions to check]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck"> + <priority>MAJOR</priority> <name><![CDATA[Javadoc Type]]></name> <configKey><![CDATA[Checker/TreeWalker/JavadocType]]></configKey> - <description><![CDATA[Checks Javadoc comments for class and interface definitions. By default, does not check for author or version tags. - The scope to verify is specified using the Scope class and defaults to Scope.PRIVATE. To verify another scope, set property scope to one of the Scope constants. - To define the format for an author tag or a version tag, set property authorFormat or versionFormat respectively to a regular expression. - <br><br>Error messages about type parameters for which no param tags are present can be suppressed by defining property allowMissingParamTags.]]></description> + <param key="scope" type="s[nothing,public,protected,package,private,anoninner]"> - <description><![CDATA[visibility scope where Javadoc comments are checked]]></description> + </param> <param key="excludeScope" type="s[nothing,public,protected,package,private,anoninner]"> - <description><![CDATA[visibility scope where Javadoc comments are not checked]]></description> + </param> <param key="authorFormat" type="r"> - <description><![CDATA[pattern for @author tag]]></description> + </param> <param key="versionFormat" type="r"> - <description><![CDATA[pattern for @version tag]]></description> + </param> <param key="allowMissingParamTags" type="b"> - <description> - <![CDATA[whether to ignore errors when a class has type parameters but does not have matching param tags in the javadoc. Default is false.]]></description> + </param> <param key="tokens" type="s[INTERFACE_DEF,CLASS_DEF]"> - <description><![CDATA[definitions to check]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocVariableCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocVariableCheck"> + <priority>MAJOR</priority> <name><![CDATA[Javadoc Variable]]></name> <configKey><![CDATA[Checker/TreeWalker/JavadocVariable]]></configKey> - <description><![CDATA[Checks that a variable has Javadoc comment.]]></description> + <param key="scope" type="s[nothing,public,protected,package,private,anoninner]"> - <description><![CDATA[visibility scope where Javadoc comments are checked]]></description> + </param> <param key="excludeScope" type="s[nothing,public,protected,package,private,anoninner]"> - <description><![CDATA[visibility scope where Javadoc comments are not checked]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.blocks.LeftCurlyCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Left Curly]]></name> <configKey><![CDATA[Checker/TreeWalker/LeftCurly]]></configKey> - <description> - <![CDATA[Checks for the placement of left curly braces for code blocks. The policy to verify is specified using property option. Policies <code>eol</code> and <code>nlow</code> take into account property maxLineLength.]]></description> + <param key="option" type="s[eol,nl,nlow]"> - <description> - <![CDATA[policy on placement of a left curly brace ('{'). eol : the brace must always be on the end of the line, nl : he brace must always be on a new line, nlow : ff the brace will fit on the first line of the statement, taking into account maximum line length, then apply eol rule. Otherwise apply the nl rule. nlow is a mnemonic for 'new line on wrap'.]]></description> + </param> <param key="maxLineLength" type="i"> - <description><![CDATA[maximum number of characters in a line. Default is 80.]]></description> + </param> <param key="tokens" type="s[CLASS_DEF,CTOR_DEF,INTERFACE_DEF,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_SWITCH,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,METHOD_DEF]"> - <description><![CDATA[blocks to check]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck"> + <priority>MAJOR</priority> <name><![CDATA[Line Length]]></name> <configKey><![CDATA[Checker/TreeWalker/LineLength]]></configKey> - <description><![CDATA[Checks for long lines.]]></description> + <param key="ignorePattern" type="r"> - <description><![CDATA[pattern for lines to ignore]]></description> + </param> <param key="max" type="i"> - <description><![CDATA[maximum allowable line length. Default is 80.]]></description> + </param> <param key="tabWidth" type="i"> - <description><![CDATA[number of expanded spaces for a tab character. Default is 8.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.naming.LocalFinalVariableNameCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.naming.LocalFinalVariableNameCheck"> + <priority>MAJOR</priority> <name><![CDATA[Local Final Variable Name]]></name> <configKey><![CDATA[Checker/TreeWalker/LocalFinalVariableName]]></configKey> - <description> - <![CDATA[Checks that local final variable names, including catch parameters, conform to the specified format]]></description> + <param key="format" type="r"> <defaultValue>^[a-z][a-zA-Z0-9]*$</defaultValue> </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.naming.LocalVariableNameCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.naming.LocalVariableNameCheck"> + <priority>MAJOR</priority> <cardinality>MULTIPLE</cardinality> <name><![CDATA[Local Variable Name]]></name> <configKey><![CDATA[Checker/TreeWalker/LocalVariableName]]></configKey> - <description> - <![CDATA[Checks that local, non-final variable names conform to the specified format]]></description> + <param key="format" type="r"> <defaultValue>^[a-z][a-zA-Z0-9]*$</defaultValue> </param> <param key="tokens" type="s[VARIABLE_DEF,PARAMETER_DEF]"> - <description> - <![CDATA[Controls whether the check applies to variable declarations or catch clause parameters]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Magic Number]]></name> <configKey><![CDATA[Checker/TreeWalker/MagicNumber]]></configKey> - <description><![CDATA[Checks for magic numbers.]]></description> + <param key="tokens" type="s[NUM_DOUBLE,NUM_FLOAT,NUM_INT,NUM_LONG]"> - <description><![CDATA[tokens to check]]></description> + </param> <param key="ignoreNumbers" type="i{}"> - <description><![CDATA[non-magic numbers. Default is -1,0,1,2.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck"> + <priority>MAJOR</priority> <cardinality>MULTIPLE</cardinality> <name><![CDATA[Member name]]></name> <configKey><![CDATA[Checker/TreeWalker/MemberName]]></configKey> - <description> - <![CDATA[Checks that name of non-static fields conform to the specified format]]></description> + <param key="format" type="r"> <defaultValue>^[a-z][a-zA-Z0-9]*$</defaultValue> </param> <param key="applyToPublic" type="b"> - <description>Controls whether to apply the check to public member</description> + <defaultValue>true</defaultValue> </param> <param key="applyToProtected" type="b"> - <description>Controls whether to apply the check to protected member</description> + <defaultValue>true</defaultValue> </param> <param key="applyToPackage" type="b"> - <description>Controls whether to apply the check to package-private member</description> + <defaultValue>true</defaultValue> </param> <param key="applyToPrivate" type="b"> - <description>Controls whether to apply the check to private member</description> + <defaultValue>true</defaultValue> </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.sizes.MethodLengthCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.sizes.MethodLengthCheck"> + <priority>MAJOR</priority> <name><![CDATA[Method Length]]></name> <configKey><![CDATA[Checker/TreeWalker/MethodLength]]></configKey> - <description><![CDATA[Checks for long methods.]]></description> + <param key="max" type="i"> - <description><![CDATA[maximum allowable number of lines. Default is 150.]]></description> + </param> <param key="countEmpty" type="b"> - <description> - <![CDATA[whether to count empty lines and single line comments of the form //. Default is true.]]></description> + </param> <param key="tokens" type="s[METHOD_DEF,CTOR_DEF]"> - <description><![CDATA[blocks to check]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.naming.MethodNameCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.naming.MethodNameCheck"> + <priority>MAJOR</priority> <name><![CDATA[Method Name]]></name> <configKey><![CDATA[Checker/TreeWalker/MethodName]]></configKey> - <description> - <![CDATA[Checks that method names conform to the specified format]]></description> + <param key="format" type="r"> <defaultValue>^[a-z][a-zA-Z0-9]*$</defaultValue> </param> <param key="allowClassName" type="b"> - <description>Controls whether to allow a method name to have the same name as the residing class name. This is not to be confused with a constructor. An easy mistake is to place a return type on a constructor declaration which turns it into a method.</description> + <defaultValue>false</defaultValue> </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.whitespace.MethodParamPadCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.whitespace.MethodParamPadCheck"> + <priority>MAJOR</priority> <name><![CDATA[Method Param Pad]]></name> <configKey><![CDATA[Checker/TreeWalker/MethodParamPad]]></configKey> - <description> - <![CDATA[Checks the padding between the identifier of a method definition, constructor definition, method call, or constructor invocation; and the left parenthesis of the parameter list.]]></description> + <param key="allowLineBreaks" type="b"> - <description> - <![CDATA[whether a line break between the identifier and left parenthesis is allowed. Default is false.]]></description> + </param> <param key="option" type="s[nospace,space]"> - <description><![CDATA[policy on how to pad method parameter. Default is nospace.]]></description> + </param> <param key="tokens" type="s[CTOR_DEF,LITERAL_NEW,METHOD_CALL,METHOD_DEF,SUPER_CTOR_CALL]"> - <description><![CDATA[tokens to check]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.MissingCtorCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.MissingCtorCheck"> + <priority>MAJOR</priority> <name><![CDATA[Missing Constructor]]></name> <configKey><![CDATA[Checker/TreeWalker/MissingCtor]]></configKey> - <description> - <![CDATA[Checks that classes (except abstract one) define a constructor and don't rely on the default one.]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.MissingSwitchDefaultCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.MissingSwitchDefaultCheck"> + <priority>MAJOR</priority> <name><![CDATA[Missing Switch Default]]></name> <configKey><![CDATA[Checker/TreeWalker/MissingSwitchDefault]]></configKey> - <description><![CDATA[Checks that switch statement has default clause.]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck"> + <priority>MAJOR</priority> <name><![CDATA[Modified Control Variable]]></name> <configKey><![CDATA[Checker/TreeWalker/ModifiedControlVariable]]></configKey> - <description> - <![CDATA[Check for ensuring that for loop control variables are not modified inside the for block.]]></description> + </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.modifier.ModifierOrderCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Modifier Order]]></name> <configKey><![CDATA[Checker/TreeWalker/ModifierOrder]]></configKey> - <description> - <![CDATA[Checks that the order of modifiers conforms to the suggestions in the Java Language specification, sections 8.1.1, 8.3.1 and 8.4.3. The correct order is : public, protected, private, abstract, static, final, transient, volatile, synchronized, native, strictfp.]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck"> + <priority>MAJOR</priority> <name><![CDATA[Multiple String Literals]]></name> <configKey><![CDATA[Checker/TreeWalker/MultipleStringLiterals]]></configKey> <cardinality>MULTIPLE</cardinality> - <description> - <![CDATA[Checks for multiple occurrences of the same string literal within a single file. Code duplication makes maintenance more difficult, so it can be better to replace the multiple occurrences with a constant.]]></description> + <param key="allowedDuplicates" type="i"> - <description> - <![CDATA[The maximum number of occurences to allow without generating a warning. Default is 1.]]></description> + </param> <param key="ignoreStringsRegexp" type="r"> - <description><![CDATA[regexp pattern for ignored strings (with quotation marks)]]></description> + </param> <param key="ignoreOccurrenceContext" type="s"> - <description> - <![CDATA[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.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.MultipleVariableDeclarationsCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.MultipleVariableDeclarationsCheck"> + <priority>MAJOR</priority> <name><![CDATA[Multiple Variable Declarations]]></name> <configKey><![CDATA[Checker/TreeWalker/MultipleVariableDeclarations]]></configKey> - <description> - <![CDATA[Checks that each variable declaration is in its own statement and on its own line.]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.design.MutableExceptionCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.design.MutableExceptionCheck"> + <priority>MAJOR</priority> <name><![CDATA[Mutable Exception]]></name> <configKey><![CDATA[Checker/TreeWalker/MutableException]]></configKey> - <description> - <![CDATA[Ensures that exceptions (defined as any class name conforming to some regular expression) are immutable.]]></description> + <param key="format" type="r"> - <description><![CDATA[pattern for name of exception class.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.metrics.NPathComplexityCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.metrics.NPathComplexityCheck"> + <priority>MAJOR</priority> <name><![CDATA[NPath Complexity]]></name> <configKey><![CDATA[Checker/TreeWalker/NPathComplexity]]></configKey> - <description> - <![CDATA[Checks the npath complexity of a method against a specified limit (default = 200). The NPATH metric computes the number of possible execution paths through a function. It takes into account the nesting of conditional statements and multi-part boolean expressions (e.g., A && B, C || D, etc.).]]></description> + <param key="max" type="i"> - <description><![CDATA[the maximum threshold allowed. Default is 200.]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Need Braces]]></name> <configKey><![CDATA[Checker/TreeWalker/NeedBraces]]></configKey> - <description><![CDATA[Checks for braces around code blocks.]]></description> + <param key="tokens" type="s[LITERAL_DO,LITERAL_ELSE,LITERAL_IF,LITERAL_FOR,LITERAL_WHILE]"> - <description><![CDATA[blocks to check]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.NestedIfDepthCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.NestedIfDepthCheck"> + <priority>MAJOR</priority> <name><![CDATA[Nested If Depth]]></name> <configKey><![CDATA[Checker/TreeWalker/NestedIfDepth]]></configKey> - <description><![CDATA[Restricts nested if-else blocks to a specified depth (default = 1).]]></description> + <param key="max" type="i"> - <description><![CDATA[allowed nesting depth. Default is 1.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.NestedTryDepthCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.NestedTryDepthCheck"> + <priority>MAJOR</priority> <name><![CDATA[Nested Try Depth]]></name> <configKey><![CDATA[Checker/TreeWalker/NestedTryDepth]]></configKey> - <description><![CDATA[Restricts nested try-catch-finally blocks to a specified depth (default = 1).]]></description> + <param key="max" type="i"> - <description><![CDATA[allowed nesting depth. Default is 1.]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Newline At End Of File]]></name> <configKey><![CDATA[Checker/NewlineAtEndOfFile]]></configKey> - <description> - <![CDATA[Checks that there is a newline at the end of each file. Any source files and text files in general should end with a newline character, especially when using SCM systems such as CVS. CVS will even print a warning when it encounters a file that doesn't end with a newline.]]></description> + <param key="lineSeparator" type="s[system,crlf,cr,lf]"> - <description> - <![CDATA[type of line separator. One of 'system' (system default), 'crlf' (Windows-style), 'cr' (Mac-style) and 'lf' (Unix-style).]]></description> + </param> <param key="fileExtensions" type="s{}"> - <description><![CDATA[file type extension of the files to check.]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[No Whitespace After]]></name> <configKey><![CDATA[Checker/TreeWalker/NoWhitespaceAfter]]></configKey> - <description><![CDATA[Checks that there is no whitespace after a token.]]></description> + <param key="allowLineBreaks" type="b"> - <description> - <![CDATA[whether whitespace is allowed if the token is at a linebreak. Default is true.]]></description> + </param> <param key="tokens" type="s[ARRAY_INIT,BNOT,DEC,DOT,INC,LNOT,UNARY_MINUS,UNARY_PLUS,TYPECAST]"> - <description><![CDATA[tokens to check]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceBeforeCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[No Whitespace Before]]></name> <configKey><![CDATA[Checker/TreeWalker/NoWhitespaceBefore]]></configKey> - <description><![CDATA[Checks that there is no whitespace before a token.]]></description> + <param key="allowLineBreaks" type="b"> - <description> - <![CDATA[whether whitespace is allowed if the token is at a linebreak. Default is false.]]></description> + </param> <param key="tokens" type="s[SEMI,DOT,POST_DEC,POST_INC]"> - <description><![CDATA[tokens to check]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Operator Wrap]]></name> <configKey><![CDATA[Checker/TreeWalker/OperatorWrap]]></configKey> - <description><![CDATA[Checks the policy on how to wrap lines on operators.]]></description> + <param key="option" type="s[nl,eol]"> - <description> - <![CDATA[policy on how to wrap lines. 'nl' : the operator must be on a new line, 'eol' : the operator must be at the end of the line. Default is 'nl'.]]></description> + </param> <param key="tokens" type="s[ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,EQUAL,GE,GT,LAND,LE,LITERAL_INSTANCEOF,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,QUESTION,SL,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN]"> - <description><![CDATA[tokens to check]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.PackageDeclarationCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.PackageDeclarationCheck"> + <priority>MAJOR</priority> <name><![CDATA[Package Declaration]]></name> <configKey><![CDATA[Checker/TreeWalker/PackageDeclaration]]></configKey> - <description><![CDATA[Ensures there is a package declaration.]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.naming.PackageNameCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.naming.PackageNameCheck"> + <priority>MAJOR</priority> <name><![CDATA[Package name]]></name> <configKey><![CDATA[Checker/TreeWalker/PackageName]]></configKey> - <description> - <![CDATA[Checks that package names conform to the specified format. The default value of format - has been chosen to match the requirements in the Java Language specification and the Sun coding conventions. - However both underscores and uppercase letters are rather uncommon, so most configurations should probably - assign value ^[a-z]+(\.[a-z][a-z0-9]*)*$ to format]]></description> + <param key="format" type="r"> <defaultValue>^[a-z]+(\.[a-zA-Z_][a-zA-Z0-9_]*)*$</defaultValue> </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.ParameterAssignmentCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.ParameterAssignmentCheck"> + <priority>MAJOR</priority> <name><![CDATA[Parameter Assignment]]></name> <configKey><![CDATA[Checker/TreeWalker/ParameterAssignment]]></configKey> - <description><![CDATA[Disallow assignment of parameters.]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.naming.ParameterNameCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.naming.ParameterNameCheck"> + <priority>MAJOR</priority> <name><![CDATA[Parameter Name]]></name> <configKey><![CDATA[Checker/TreeWalker/ParameterName]]></configKey> - <description> - <![CDATA[Checks that parameter names conform to the specified format]]></description> + <param key="format" type="r"> <defaultValue>^[a-z][a-zA-Z0-9]*$</defaultValue> </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck"> + <priority>MAJOR</priority> <name><![CDATA[Parameter Number]]></name> <configKey><![CDATA[Checker/TreeWalker/ParameterNumber]]></configKey> - <description><![CDATA[Checks the number of parameters that a method or constructor has.]]></description> + <param key="max" type="i"> - <description><![CDATA[maximum allowable number of parameters. Default is 7.]]></description> + </param> <param key="tokens" type="s[METHOD_DEF,CTOR_DEF]"> - <description><![CDATA[declarations to check]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.whitespace.ParenPadCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Paren Pad]]></name> <configKey><![CDATA[Checker/TreeWalker/ParenPad]]></configKey> - <description> - <![CDATA[Checks the padding of parentheses; that is whether a space is required after a left parenthesis and before a right parenthesis, or such spaces are forbidden, with the exception that it does not check for padding of the right parenthesis at an empty for iterator.]]></description> + <param key="option" type="s[nospace,space]"> - <description><![CDATA[policy on how to pad parentheses]]></description> + </param> <param key="tokens" type="s[CTOR_CALL,LPAREN,METHOD_CALL,RPAREN,SUPER_CTOR_CALL]"> - <description><![CDATA[tokens to check]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.modifier.RedundantModifierCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Redundant Modifier]]></name> <configKey><![CDATA[Checker/TreeWalker/RedundantModifier]]></configKey> - <description><![CDATA[Checks for redundant modifiers in interface and annotation definitions.]]></description> + <param key="tokens" type="s[METHOD_DEF,VARIABLE_DEF,ANNOTATION_FIELD_DEF]"> - <description><![CDATA[tokens to check]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.coding.RedundantThrowsCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Redundant Throws]]></name> <configKey><![CDATA[Checker/TreeWalker/RedundantThrows]]></configKey> - <description> - <![CDATA[Checks for redundant exceptions declared in throws clause such as duplicates, unchecked exceptions or subclasses of another declared exception.]]></description> + <param key="allowUnchecked" type="b"> - <description> - <![CDATA[whether unchecked exceptions in throws are allowed or not. Default is false.]]></description> + </param> <param key="allowSubclasses" type="b"> - <description> - <![CDATA[whether subclass of another declared exception is allowed in throws clause. Default is false.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.RegexpCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.RegexpCheck"> + <priority>MAJOR</priority> <name><![CDATA[Regexp]]></name> <configKey><![CDATA[Checker/TreeWalker/Regexp]]></configKey> <cardinality>MULTIPLE</cardinality> - <description><![CDATA[A check that makes sure that a specified pattern exists (or not) in the file.]]></description> + <param key="format" type="r"> - <description><![CDATA[pattern]]></description> + </param> <param key="message" type="s"> - <description> - <![CDATA[message which is used to notify about violations, if empty then default(hard-coded) message is used.]]></description> + </param> <param key="illegalPattern" type="b"> - <description><![CDATA[Controls whether the pattern is required or illegal. Default is false.]]></description> + </param> <param key="duplicateLimit" type="i"> - <description> - <![CDATA[Controls whether to check for duplicates of a required pattern, any negative value means no checking for duplicates, any positive value is used as the maximum number of allowed duplicates, if the limit is exceeded errors will be logged. Default is -1.]]></description> + </param> <param key="errorLimit" type="i"> - <description> - <![CDATA[Controls the maximum number of errors before the check will abort. Default is 100.]]></description> + </param> <param key="ignoreComments" type="b"> - <description><![CDATA[Controls whether to ignore matches found within comments. Default is false.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.RequireThisCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.RequireThisCheck"> + <priority>MAJOR</priority> <name><![CDATA[Require This]]></name> <configKey><![CDATA[Checker/TreeWalker/RequireThis]]></configKey> - <description><![CDATA[Checks that code doesn't rely on the this default.]]></description> + <param key="checkFields" type="b"> - <description><![CDATA[whether we should check fields usage or not. Default is true.]]></description> + </param> <param key="checkMethods" type="b"> - <description><![CDATA[whether we should check methods usage or not. Default is true.]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.ReturnCountCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.ReturnCountCheck"> + <priority>MAJOR</priority> <name><![CDATA[Return Count]]></name> <configKey><![CDATA[Checker/TreeWalker/ReturnCount]]></configKey> - <description><![CDATA[Restricts return statements to a specified count (default = 2).]]></description> + <param key="max" type="i"> - <description><![CDATA[maximum allowed number of return statments]]></description> + </param> <param key="format" type="r"> - <description><![CDATA[method names to ingone]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Right Curly]]></name> <configKey><![CDATA[Checker/TreeWalker/RightCurly]]></configKey> - <description><![CDATA[Checks the placement of right curly braces.]]></description> + <param key="option" type="s[same,alone]"> - <description><![CDATA[policy on placement of a right curly brace ('}')]]></description> + </param> <param key="tokens" type="s[LITERAL_TRY,LITERAL_CATCH,LITERAL_FINALLY,LITERAL_IF,LITERAL_ELSE]"> - <description><![CDATA[blocks to check]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.SimplifyBooleanExpressionCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.SimplifyBooleanExpressionCheck"> + <priority>MAJOR</priority> <name><![CDATA[Simplify Boolean Expression]]></name> <configKey><![CDATA[Checker/TreeWalker/SimplifyBooleanExpression]]></configKey> - <description><![CDATA[Checks for overly complicated boolean expressions.]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.SimplifyBooleanReturnCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.SimplifyBooleanReturnCheck"> + <priority>MAJOR</priority> <name><![CDATA[Simplify Boolean Return]]></name> <configKey><![CDATA[Checker/TreeWalker/SimplifyBooleanReturn]]></configKey> - <description><![CDATA[Checks for overly complicated boolean return statements.]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.naming.StaticVariableNameCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.naming.StaticVariableNameCheck"> + <priority>MAJOR</priority> <name><![CDATA[Static Variable Name]]></name> <configKey><![CDATA[Checker/TreeWalker/StaticVariableName]]></configKey> <cardinality>MULTIPLE</cardinality> - <description> - <![CDATA[Checks that static, non-final fields conform to the specified format]]></description> + <param key="format" type="r"> <defaultValue>^[a-z][a-zA-Z0-9]*$</defaultValue> </param> <param key="applyToPublic" type="b"> - <description>Controls whether to apply the check to public member</description> + <defaultValue>true</defaultValue> </param> <param key="applyToProtected" type="b"> - <description>Controls whether to apply the check to protected member</description> + <defaultValue>true</defaultValue> </param> <param key="applyToPackage" type="b"> - <description>Controls whether to apply the check to package-private member</description> + <defaultValue>true</defaultValue> </param> <param key="applyToPrivate" type="b"> - <description>Controls whether to apply the check to private member</description> + <defaultValue>true</defaultValue> </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.duplicates.StrictDuplicateCodeCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.duplicates.StrictDuplicateCodeCheck"> + <priority>MAJOR</priority> <name><![CDATA[Strict Duplicate Code]]></name> <configKey><![CDATA[Checker/StrictDuplicateCode]]></configKey> - <description> - <![CDATA[Performs a line-by-line comparison of all code lines and reports duplicate code if a sequence of lines differs only in indentation.]]></description> + <param key="min" type="i"> - <description><![CDATA[how many lines must be equal to be considered a duplicate. Default is 12.]]></description> + </param> <param key="charset" type="s"> - <description><![CDATA[name of the file charset]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.StringLiteralEqualityCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.StringLiteralEqualityCheck"> + <priority>MAJOR</priority> <name><![CDATA[String Literal Equality]]></name> <configKey><![CDATA[Checker/TreeWalker/StringLiteralEquality]]></configKey> - <description><![CDATA[Checks that string literals are not used with == or !=.]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.SuperCloneCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.SuperCloneCheck"> + <priority>MAJOR</priority> <name><![CDATA[Super Clone]]></name> <configKey><![CDATA[Checker/TreeWalker/SuperClone]]></configKey> - <description><![CDATA[Checks that an overriding clone() method invokes super.clone().]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.coding.SuperFinalizeCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.coding.SuperFinalizeCheck"> + <priority>MAJOR</priority> <name><![CDATA[Super Finalize]]></name> <configKey><![CDATA[Checker/TreeWalker/SuperFinalize]]></configKey> - <description><![CDATA[Checks that an overriding finalize() method invokes super.finalize().]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.design.ThrowsCountCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.design.ThrowsCountCheck"> + <priority>MAJOR</priority> <name><![CDATA[Throws Count]]></name> <configKey><![CDATA[Checker/TreeWalker/ThrowsCount]]></configKey> - <description><![CDATA[Restricts throws statements to a specified count (default = 1).]]></description> + <param key="max" type="i"> - <description><![CDATA[maximum allowed number of throws statments]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Comment pattern matcher]]></name> <configKey><![CDATA[Checker/TreeWalker/TodoComment]]></configKey> <cardinality>MULTIPLE</cardinality> - <description><![CDATA[This rule allows to find any kind of pattern inside comments like TODO, NOPMD, ..., except NOSONAR]]></description> + <param key="format" type="r"> - <description><![CDATA[Regular expression pattern to check. Default is TODO:]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.indentation.TrailingCommentCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Trailing Comment]]></name> <configKey><![CDATA[Checker/TreeWalker/TrailingComment]]></configKey> - <description><![CDATA[The check to ensure that requires that comments be the only thing on a line.]]></description> + <param key="format" type="r"> - <description><![CDATA[pattern for string allowed before comment.]]></description> + </param> <param key="legalComment" type="r"> - <description> - <![CDATA[pattern for text of trailing comment which is allowed. (this patter will not be applied to multiline comments and text of comment will be trimmed before matching)]]></description> + </param> </rule> - <!-- + <!-- Deactivated. See http://jira.codehaus.org/browse/SONAR-1698 <rule key="com.puppycrawl.tools.checkstyle.checks.TranslationCheck"> @@ -1705,156 +1445,148 @@ Rationale: Too large methods and classes are hard to read and costly to maintain <name><![CDATA[Translation]]></name> <configKey><![CDATA[Checker/Translation]]></configKey> - <description> - <![CDATA[Ensures the correct translation of code by checking property files for consistency regarding their keys. Two property files describing one and the same context are consistent if they contain the same keys.]]></description> + <param key="fileExtensions" type="s{}"> - <description> - <![CDATA[File type extension to identify translation files. Setting this property is typically only required if your translation files are preprocessed and the original files do not have the extension .properties.]]></description> + </param> </rule>--> - <rule key="com.puppycrawl.tools.checkstyle.checks.naming.TypeNameCheck" > + <rule key="com.puppycrawl.tools.checkstyle.checks.naming.TypeNameCheck"> <priority>MAJOR</priority> <name><![CDATA[Type Name]]></name> <configKey><![CDATA[Checker/TreeWalker/TypeName]]></configKey> <cardinality>MULTIPLE</cardinality> - <description><![CDATA[Checks that type names conform to the specified format]]></description> + <param key="format" type="r"> <defaultValue>^[A-Z][a-zA-Z0-9]*$</defaultValue> </param> <param key="tokens" type="s[CLASS_DEF,INTERFACE_DEF]"> - <description><![CDATA[Control whether the check applies to classes or interfaces]]></description> + </param> <param key="applyToPublic" type="b"> - <description>Controls whether to apply the check to public member</description> + <defaultValue>true</defaultValue> </param> <param key="applyToProtected" type="b"> - <description>Controls whether to apply the check to protected member</description> + <defaultValue>true</defaultValue> </param> <param key="applyToPackage" type="b"> - <description>Controls whether to apply the check to package-private member</description> + <defaultValue>true</defaultValue> </param> <param key="applyToPrivate" type="b"> - <description>Controls whether to apply the check to private member</description> + <defaultValue>true</defaultValue> </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.whitespace.TypecastParenPadCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.whitespace.TypecastParenPadCheck"> + <priority>MAJOR</priority> <name><![CDATA[Typecast Paren Pad]]></name> <configKey><![CDATA[Checker/TreeWalker/TypecastParenPad]]></configKey> - <description><![CDATA[Checks the padding of parentheses for typecasts.]]></description> + <param key="option" type="s[nospace,space]"> - <description><![CDATA[policy on how to pad parentheses]]></description> + </param> <param key="tokens" type="s[TYPECAST,RPAREN]"> - <description><![CDATA[tokens to check]]></description> + </param> </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.UncommentedMainCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.UncommentedMainCheck"> + <priority>MAJOR</priority> <name><![CDATA[Uncommented Main]]></name> <configKey><![CDATA[Checker/TreeWalker/UncommentedMain]]></configKey> - <description><![CDATA[Detects uncommented main methods.]]></description> + <param key="excludedClasses" type="r"> - <description> - <![CDATA[pattern for qualified names of classes which are allowed to have a main method.]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.coding.UnnecessaryParenthesesCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Unnecessary Parentheses]]></name> <configKey><![CDATA[Checker/TreeWalker/UnnecessaryParentheses]]></configKey> - <description><![CDATA[Checks if unnecessary parentheses are used in a statement or expression.]]></description> + </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck"> -<priority>INFO</priority> + <priority>INFO</priority> <name><![CDATA[Unused Imports]]></name> <configKey><![CDATA[Checker/TreeWalker/UnusedImports]]></configKey> - <description><![CDATA[Checks for unused import statements.]]></description> + </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.UpperEllCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Upper Ell]]></name> <configKey><![CDATA[Checker/TreeWalker/UpperEll]]></configKey> - <description><![CDATA[Checks that long constants are defined with an upper ell. That is ' L' and not 'l'. - This is in accordance to the Java Language Specification, <a href="http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#48282">Section 3.10.1</a>.]]></description> + </rule> - <rule key="com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck" > -<priority>MAJOR</priority> + <rule key="com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck"> + <priority>MAJOR</priority> <name><![CDATA[Visibility Modifier]]></name> <configKey><![CDATA[Checker/TreeWalker/VisibilityModifier]]></configKey> - <description> - <![CDATA[Checks visibility of class members. Only static final members may be public; other class members must be private unless property protectedAllowed or packageAllowed is set.]]></description> + <param key="packageAllowed" type="b"> - <description><![CDATA[whether package visible members are allowed. Default is false.]]></description> + </param> <param key="protectedAllowed" type="b"> - <description><![CDATA[whether protected members are allowed. Default is false.]]></description> + </param> <param key="publicMemberPattern" type="r"> - <description> - <![CDATA[pattern for public members that should be ignored. Default is ^serialVersionUID$.]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Whitespace After]]></name> <configKey><![CDATA[Checker/TreeWalker/WhitespaceAfter]]></configKey> - <description> - <![CDATA[Checks that a token is followed by whitespace, with the exception that it does not check for whitespace after the semicolon of an empty for iterator.]]></description> + <param key="tokens" type="s[COMMA,SEMI,TYPECAST]"> - <description><![CDATA[tokens to check]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Whitespace Around]]></name> <configKey><![CDATA[Checker/TreeWalker/WhitespaceAround]]></configKey> - <description><![CDATA[Checks that a token is surrounded by whitespace.]]></description> + <param key="tokens" type="s[ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,EQUAL,GE,GT,LAND,LCURLY,LE,LITERAL_ASSERT,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,QUESTION,RCURLY,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,GENERIC_START,GENERIC_END,TYPE_EXTENSION_AND,WILDCARD_TYPE]"> - <description><![CDATA[tokens to check]]></description> + </param> <param key="allowEmptyConstructors" type="b"> - <description><![CDATA[allow empty constructor bodies. Default is false.]]></description> + </param> <param key="allowEmptyMethods" type="b"> - <description><![CDATA[allow empty method bodies. Default is false.]]></description> + </param> </rule> <rule key="com.puppycrawl.tools.checkstyle.checks.javadoc.WriteTagCheck"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Write Tag]]></name> <configKey><![CDATA[Checker/TreeWalker/WriteTag]]></configKey> - <description> - <![CDATA[Outputs a JavaDoc tag as information. Can be used e.g. with the stylesheets that sort the report by author name. To define the format for a tag, set property tagFormat to a regular expression. This check uses two different severity levels. The normal one is used for reporting when the tag is missing. The additional one (tagSeverity) is used for the level of reporting when the tag exists.]]></description> + <param key="tag" type="s"> - <description><![CDATA[Name of tag]]></description> + </param> <param key="tagFormat" type="r"> - <description><![CDATA[Format of tag]]></description> + </param> <param key="tagSeverity" type="s[ignore,info,warning,error]"> - <description><![CDATA[Severity level when tag is found and printed. Default is info.]]></description> + </param> </rule> </rules>
\ No newline at end of file diff --git a/plugins/sonar-findbugs-plugin/src/main/resources/org/sonar/plugins/findbugs/rules.xml b/plugins/sonar-findbugs-plugin/src/main/resources/org/sonar/plugins/findbugs/rules.xml index bcd34822b75..21354a6c852 100644 --- a/plugins/sonar-findbugs-plugin/src/main/resources/org/sonar/plugins/findbugs/rules.xml +++ b/plugins/sonar-findbugs-plugin/src/main/resources/org/sonar/plugins/findbugs/rules.xml @@ -1,4931 +1,2754 @@ <rules> <!-- Findbugs 1.3.9 --> <rule key="BC_IMPOSSIBLE_DOWNCAST"> -<priority>BLOCKER</priority> + <priority>BLOCKER</priority> <name><![CDATA[Correctness - Impossible downcast]]></name> <configKey><![CDATA[BC_IMPOSSIBLE_DOWNCAST]]></configKey> - - <description> - <![CDATA[This cast will always throw a ClassCastException. The analysis believes it knows the precise type of the value being cast, and the attempt to downcast it to a subtype will always fail by throwing a ClassCastException.]]></description> + + </rule> <rule key="BC_IMPOSSIBLE_DOWNCAST_OF_TOARRAY"> -<priority>BLOCKER</priority> + <priority>BLOCKER</priority> <name><![CDATA[Correctness - Impossible downcast of toArray() result]]></name> <configKey><![CDATA[BC_IMPOSSIBLE_DOWNCAST_OF_TOARRAY]]></configKey> - - <description><![CDATA[<p>This code is casting the result of calling toArray() on a collection to a type more specific than Object[], as in:</p> -<pre> - String[] getAsArray(Collection<String> c) { - return (String[]) c.toArray(); - } -</pre> -<p>This will usually fail by throwing a ClassCastException. The <code>toArray()</code> of almost all collections return an <code>Object[]</code>. They can't really do anything else, since the Collection object has no reference to the declared generic type of the collection.</p> -<p>The correct way to do get an array of a specific type from a collection is to use <code>c.toArray(new String[]);</code> or <code>c.toArray(new String[c.size()]);</code> (the latter is slightly more efficient).</p> -<p>There is one common/known exception exception to this. The toArray() method of lists returned by Arrays.asList(...) will return a covariantly typed array. For example, <code>Arrays.asArray(new String[] { "a" }).toArray()</code> will return a String []. FindBugs attempts to detect and suppress such cases, but may miss some.</p>]]></description> + + </rule> <rule key="EC_INCOMPATIBLE_ARRAY_COMPARE"> -<priority>BLOCKER</priority> + <priority>BLOCKER</priority> <name><![CDATA[Correctness - equals(...) used to compare incompatible arrays]]></name> <configKey><![CDATA[EC_INCOMPATIBLE_ARRAY_COMPARE]]></configKey> - - <description> - <![CDATA[This method invokes the .equals(Object o) to compare two arrays, but the arrays of of incompatible types (e.g., String[] and StringBuffer[], or String[] and int[]). They will never be equal. In addition, when equals(...) is used to compare arrays it only checks to see if they are the same array, and ignores the contents of the arrays.]]></description> + + </rule> <rule key="EC_INCOMPATIBLE_ARRAY_COMPARE"> -<priority>BLOCKER</priority> + <priority>BLOCKER</priority> <name><![CDATA[Correctness - equals(...) used to compare incompatible arrays]]></name> <configKey><![CDATA[EC_INCOMPATIBLE_ARRAY_COMPARE]]></configKey> - - <description> - <![CDATA[This method invokes the .equals(Object o) to compare two arrays, but the arrays of of incompatible types (e.g., String[] and StringBuffer[], or String[] and int[]). They will never be equal. In addition, when equals(...) is used to compare arrays it only checks to see if they are the same array, and ignores the contents of the arrays.]]></description> + + </rule> <rule key="LG_LOST_LOGGER_DUE_TO_WEAK_REFERENCE"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Potential lost logger changes due to weak reference in OpenJDK ]]></name> <configKey><![CDATA[LG_LOST_LOGGER_DUE_TO_WEAK_REFERENCE]]></configKey> - - <description><![CDATA[<p>OpenJDK introduces a potential incompatibility. In particular, the java.util.logging.Logger behavior has changed. Instead of using strong references, it now uses weak references internally. That's a reasonable change, but unfortunately some code relies on the old behavior - when changing logger configuration, it simply drops the logger reference. That means that the garbage collector is free to reclaim that memory, which means that the logger configuration is lost. For example, consider:</p> -</pre> - public static void initLogging() throws Exception { - Logger logger = Logger.getLogger("edu.umd.cs"); - logger.addHandler(new FileHandler()); // call to change logger configuration - logger.setUseParentHandlers(false); // another call to change logger configuration - } -</pre> -<p>The logger reference is lost at the end of the method (it doesn't escape the method), so if you have a garbage collection cycle just after the call to initLogging, the logger configuration is lost (because Logger only keeps weak references).</p> -<pre> - public static void main(String[] args) throws Exception { - initLogging(); // adds a file handler to the logger - System.gc(); // logger configuration lost - Logger.getLogger("edu.umd.cs").info("Some message"); // this isn't logged to the file as expected - } -</pre> -]]></description> + + </rule> <rule key="NP_CLOSING_NULL"> -<priority>BLOCKER</priority> + <priority>BLOCKER</priority> <name><![CDATA[Correctness - close() invoked on a value that is always null]]></name> <configKey><![CDATA[NP_CLOSING_NULL]]></configKey> - - <description> - <![CDATA[close() is being invoked on a value that is always null. If this statement is executed, a null pointer exception will occur. But the big risk here you never close something that should be closed.]]></description> + + </rule> <rule key="RC_REF_COMPARISON_BAD_PRACTICE"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Suspicious reference comparison to constant]]></name> <configKey><![CDATA[RC_REF_COMPARISON_BAD_PRACTICE]]></configKey> - - <description> - <![CDATA[This method compares a reference value to a constant using the == or != operator, where the correct way to compare instances of this type is generally with the equals() method. It is possible to create distinct instances that are equal but do not compare as == since they are different objects. Examples of classes which should generally not be compared by reference are java.lang.Integer, java.lang.Float, etc.]]></description> + + </rule> <rule key="RC_REF_COMPARISON_BAD_PRACTICE_BOOLEAN"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Suspicious reference comparison of Boolean values]]></name> <configKey><![CDATA[RC_REF_COMPARISON_BAD_PRACTICE_BOOLEAN]]></configKey> - - <description> - <![CDATA[This method compares two Boolean values using the == or != operator. Normally, there are only two Boolean values (Boolean.TRUE and Boolean.FALSE), but it is possible to create other Boolean objects using the new Boolean(b) constructor. It is best to avoid such objects, but if they do exist, then checking Boolean objects for equality using == or != will give results than are different than you would get using .equals(...)]]></description> + + </rule> <rule key="RV_RETURN_VALUE_OF_PUTIFABSENT_IGNORED"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Return value of putIfAbsent ignored, value passed to putIfAbsent reused ]]></name> <configKey><![CDATA[RV_RETURN_VALUE_OF_PUTIFABSENT_IGNORED]]></configKey> - - <description> - <![CDATA[The putIfAbsent method is typically used to ensure that a single value is associated with a given key (the first value for which put if absent succeeds). If you ignore the return value and retain a reference to the value passed in, you run the risk of retaining a value that is not the one that is associated with the key in the map. If it matters which one you use and you use the one that isn't stored in the map, your program will behave incorrectly.]]></description> + + </rule> <rule key="SIC_THREADLOCAL_DEADLY_EMBRACE"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Deadly embrace of non-static inner class and thread local]]></name> <configKey><![CDATA[SIC_THREADLOCAL_DEADLY_EMBRACE]]></configKey> - - <description> - <![CDATA[This class is an inner class, but should probably be a static inner class. As it is, there is a serious danger of a deadly embrace between the inner class and the thread local in the outer class. Because the inner class isn't static, it retains a reference to the outer class. If the thread local contains a reference to an instance of the inner class, the inner and outer instance will both be reachable and not eligible for garbage collection.]]></description> + + </rule> <rule key="UR_UNINIT_READ_CALLED_FROM_SUPER_CONSTRUCTOR"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Uninitialized read of field method called from constructor of superclass]]></name> <configKey><![CDATA[UR_UNINIT_READ_CALLED_FROM_SUPER_CONSTRUCTOR]]></configKey> - - <description><![CDATA[<p>This method is invoked in the constructor of of the superclass. At this point, the fields of the class have not yet initialized. To make this more concrete, consider the following classes:</p> -<pre> - abstract class A { - int hashCode; - abstract Object getValue(); - A() { - hashCode = getValue().hashCode(); - } - } - class B extends A { - Object value; - B(Object v) { - this.value = v; - } - Object getValue() { - return value; - } - } -</pre> -<p>When a B is constructed, the constructor for the A class is invoked before the constructor for B sets value. Thus, when the constructor for A invokes getValue, an uninitialized value is read for value.</p>]]></description> + + </rule> <rule key="VA_FORMAT_STRING_EXPECTED_MESSAGE_FORMAT_SUPPLIED"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - MessageFormat supplied where printf style format expected ]]></name> <configKey><![CDATA[VA_FORMAT_STRING_EXPECTED_MESSAGE_FORMAT_SUPPLIED]]></configKey> - - <description> - <![CDATA[A method is called that expects a Java printf format string and a list of arguments. However, the format string doesn't contain any format specifiers (e.g., %s) but does contain message format elements (e.g., {0}). It is likely that the code is supplying a MessageFormat string when a printf-style format string is required. At runtime, all of the arguments will be ignored and the format string will be returned exactly as provided without any formatting.]]></description> + + </rule> <!-- Before Findbugs 1.3.9 --> <rule key="UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Correctness - Field not initialized in constructor]]></name> <configKey><![CDATA[UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR]]></configKey> - - <description><![CDATA[<p>This field is never initialized within any constructor, and is therefore could be null after the object is constructed. This could be a either an error or a questionable design, since it means a null pointer exception will be generated if that field is dereferenced before being initialized.</p>]]></description> + + </rule> <rule key="NP_UNWRITTEN_FIELD"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Read of unwritten field]]></name> <configKey><![CDATA[NP_UNWRITTEN_FIELD]]></configKey> - - <description><![CDATA[<p>The program is dereferencing a field that does not seem to ever have a non-null value written to it. Dereferencing this value will generate a null pointer exception.</p>]]></description> + + </rule> <rule key="UWF_UNWRITTEN_FIELD"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Correctness - Unwritten field]]></name> <configKey><![CDATA[UWF_UNWRITTEN_FIELD]]></configKey> - - <description><![CDATA[<p>This field is never written. All reads of it will return the default value. Check for errors (should it have been initialized?), or remove it if it is useless.</p>]]></description> + + </rule> <rule key="SKIPPED_CLASS_TOO_BIG"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Dodgy - Class too big for analysis]]></name> <configKey><![CDATA[SKIPPED_CLASS_TOO_BIG]]></configKey> - - <description><![CDATA[<p>This class is bigger than can be effectively handled, and was not fully analyzed for errors. -</p>]]></description> + + </rule> <rule key="DMI_SCHEDULED_THREAD_POOL_EXECUTOR_WITH_ZERO_CORE_THREADS"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Correctness - Creation of ScheduledThreadPoolExecutor with zero core threads]]></name> <configKey><![CDATA[DMI_SCHEDULED_THREAD_POOL_EXECUTOR_WITH_ZERO_CORE_THREADS]]></configKey> - - <description><![CDATA[<p>(<a href="http://java.sun.com/javase/6/docs/api/java/util/concurrent/ScheduledThreadPoolExecutor.html#ScheduledThreadPoolExecutor(int)">Javadoc</a>) -A ScheduledThreadPoolExecutor with zero core threads will never execute anything; changes to the max pool size are ignored. -</p>]]></description> + + </rule> <rule key="DMI_FUTILE_ATTEMPT_TO_CHANGE_MAXPOOL_SIZE_OF_SCHEDULED_THREAD_POOL_EXECUTOR"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Correctness - Futile attempt to change max pool size of ScheduledThreadPoolExecutor]]></name> <configKey><![CDATA[DMI_FUTILE_ATTEMPT_TO_CHANGE_MAXPOOL_SIZE_OF_SCHEDULED_THREAD_POOL_EXECUTOR]]></configKey> - - <description><![CDATA[<p>(<a href="http://java.sun.com/javase/6/docs/api/java/util/concurrent/ScheduledThreadPoolExecutor.html">Javadoc</a>) -While ScheduledThreadPoolExecutor inherits from ThreadPoolExecutor, a few of the inherited tuning methods are not useful for it. In particular, because it acts as a fixed-sized pool using corePoolSize threads and an unbounded queue, adjustments to maximumPoolSize have no useful effect. - </p>]]></description> + + </rule> <rule key="DMI_UNSUPPORTED_METHOD"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Dodgy - Call to unsupported method]]></name> <configKey><![CDATA[DMI_UNSUPPORTED_METHOD]]></configKey> - - <description><![CDATA[<p>All targets of this method invocation throw an UnsupportedOperationException. -</p>]]></description> + + </rule> <rule key="DMI_EMPTY_DB_PASSWORD"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Security - Empty database password]]></name> <configKey><![CDATA[DMI_EMPTY_DB_PASSWORD]]></configKey> - - <description><![CDATA[<p>This code creates a database connect using a blank or empty password. This indicates that the database is not protected by a password. -</p>]]></description> + + </rule> <rule key="DMI_CONSTANT_DB_PASSWORD"> -<priority>BLOCKER</priority> + <priority>BLOCKER</priority> <name><![CDATA[Security - Hardcoded constant database password]]></name> <configKey><![CDATA[DMI_CONSTANT_DB_PASSWORD]]></configKey> - - <description><![CDATA[<p>This code creates a database connect using a hardcoded, constant password. Anyone with access to either the source code or the compiled code can - easily learn the password. -</p>]]></description> + + </rule> <rule key="HRS_REQUEST_PARAMETER_TO_COOKIE"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Security - HTTP cookie formed from untrusted input]]></name> <configKey><![CDATA[HRS_REQUEST_PARAMETER_TO_COOKIE]]></configKey> - - <description><![CDATA[<p>This code constructs an HTTP Cookie using an untrusted HTTP parameter. If this cookie is added to an HTTP response, it will allow a HTTP response splitting -vulnerability. See <a href="http://en.wikipedia.org/wiki/HTTP_response_splitting">http://en.wikipedia.org/wiki/HTTP_response_splitting</a> -for more information.</p> -<p>FindBugs looks only for the most blatant, obvious cases of HTTP response splitting. -If FindBugs found <em>any</em>, you <em>almost certainly</em> have more -vulnerabilities that FindBugs doesn't report. If you are concerned about HTTP response splitting, you should seriously -consider using a commercial static analysis or pen-testing tool. -</p>]]></description> + + </rule> <rule key="HRS_REQUEST_PARAMETER_TO_HTTP_HEADER"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Security - HTTP Response splitting vulnerability]]></name> <configKey><![CDATA[HRS_REQUEST_PARAMETER_TO_HTTP_HEADER]]></configKey> - - <description><![CDATA[<p>This code directly writes an HTTP parameter to an HTTP header, which allows for a HTTP response splitting -vulnerability. See <a href="http://en.wikipedia.org/wiki/HTTP_response_splitting">http://en.wikipedia.org/wiki/HTTP_response_splitting</a> -for more information.</p> -<p>FindBugs looks only for the most blatant, obvious cases of HTTP response splitting. -If FindBugs found <em>any</em>, you <em>almost certainly</em> have more -vulnerabilities that FindBugs doesn't report. If you are concerned about HTTP response splitting, you should seriously -consider using a commercial static analysis or pen-testing tool. -</p>]]></description> + + </rule> <rule key="XSS_REQUEST_PARAMETER_TO_SERVLET_WRITER"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Security - Servlet reflected cross site scripting vulnerability]]></name> <configKey><![CDATA[XSS_REQUEST_PARAMETER_TO_SERVLET_WRITER]]></configKey> - - <description><![CDATA[<p>This code directly writes an HTTP parameter to Servlet output, which allows for a reflected cross site scripting -vulnerability. See <a href="http://en.wikipedia.org/wiki/Cross-site_scripting">http://en.wikipedia.org/wiki/Cross-site_scripting</a> -for more information.</p> -<p>FindBugs looks only for the most blatant, obvious cases of cross site scripting. -If FindBugs found <em>any</em>, you <em>almost certainly</em> have more cross site scripting -vulnerabilities that FindBugs doesn't report. If you are concerned about cross site scripting, you should seriously -consider using a commercial static analysis or pen-testing tool. -</p>]]></description> + + </rule> <rule key="XSS_REQUEST_PARAMETER_TO_SEND_ERROR"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Security - Servlet reflected cross site scripting vulnerability]]></name> <configKey><![CDATA[XSS_REQUEST_PARAMETER_TO_SEND_ERROR]]></configKey> - - <description><![CDATA[<p>This code directly writes an HTTP parameter to a Server error page (using HttpServletResponse.sendError). Echoing this untrusted input allows -for a reflected cross site scripting -vulnerability. See <a href="http://en.wikipedia.org/wiki/Cross-site_scripting">http://en.wikipedia.org/wiki/Cross-site_scripting</a> -for more information.</p> -<p>FindBugs looks only for the most blatant, obvious cases of cross site scripting. -If FindBugs found <em>any</em>, you <em>almost certainly</em> have more cross site scripting -vulnerabilities that FindBugs doesn't report. If you are concerned about cross site scripting, you should seriously -consider using a commercial static analysis or pen-testing tool. -</p>]]></description> + + </rule> <rule key="XSS_REQUEST_PARAMETER_TO_JSP_WRITER"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Security - JSP reflected cross site scripting vulnerability]]></name> <configKey><![CDATA[XSS_REQUEST_PARAMETER_TO_JSP_WRITER]]></configKey> - - <description><![CDATA[<p>This code directly writes an HTTP parameter to JSP output, which allows for a cross site scripting -vulnerability. See <a href="http://en.wikipedia.org/wiki/Cross-site_scripting">http://en.wikipedia.org/wiki/Cross-site_scripting</a> -for more information.</p> -<p>FindBugs looks only for the most blatant, obvious cases of cross site scripting. -If FindBugs found <em>any</em>, you <em>almost certainly</em> have more cross site scripting -vulnerabilities that FindBugs doesn't report. If you are concerned about cross site scripting, you should seriously -consider using a commercial static analysis or pen-testing tool. -</p>]]></description> + + </rule> <rule key="SW_SWING_METHODS_INVOKED_IN_SWING_THREAD"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Certain swing methods needs to be invoked in Swing thread]]></name> <configKey><![CDATA[SW_SWING_METHODS_INVOKED_IN_SWING_THREAD]]></configKey> - - <description><![CDATA[<p>(<a href="http://java.sun.com/developer/JDCTechTips/2003/tt1208.html#1">From JDC Tech Tip</a>): The Swing methods -show(), setVisible(), and pack() will create the associated peer for the frame. -With the creation of the peer, the system creates the event dispatch thread. -This makes things problematic because the event dispatch thread could be notifying -listeners while pack and validate are still processing. This situation could result in -two threads going through the Swing component-based GUI -- it's a serious flaw that -could result in deadlocks or other related threading issues. A pack call causes -components to be realized. As they are being realized (that is, not necessarily -visible), they could trigger listener notification on the event dispatch thread.</p>]]></description> + + </rule> <rule key="IL_INFINITE_LOOP"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - An apparent infinite loop]]></name> <configKey><![CDATA[IL_INFINITE_LOOP]]></configKey> - - <description><![CDATA[<p>This loop doesn't seem to have a way to terminate (other than by perhaps -throwing an exception).</p>]]></description> + + </rule> <rule key="IL_INFINITE_RECURSIVE_LOOP"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - An apparent infinite recursive loop]]></name> <configKey><![CDATA[IL_INFINITE_RECURSIVE_LOOP]]></configKey> - - <description><![CDATA[<p>This method unconditionally invokes itself. This would seem to indicate -an infinite recursive loop that will result in a stack overflow.</p>]]></description> + + </rule> <rule key="IL_CONTAINER_ADDED_TO_ITSELF"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - A collection is added to itself]]></name> <configKey><![CDATA[IL_CONTAINER_ADDED_TO_ITSELF]]></configKey> - - <description><![CDATA[<p>A collection is added to itself. As a result, computing the hashCode of this -set will throw a StackOverflowException. -</p>]]></description> + + </rule> <rule key="VO_VOLATILE_REFERENCE_TO_ARRAY"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name> <![CDATA[Multithreaded correctness - A volatile reference to an array doesn't treat the array elements as volatile]]></name> <configKey><![CDATA[VO_VOLATILE_REFERENCE_TO_ARRAY]]></configKey> - - <description><![CDATA[<p>This declares a volatile reference to an array, which might not be what -you want. With a volatile reference to an array, reads and writes of -the reference to the array are treated as volatile, but the array elements -are non-volatile. To get volatile array elements, you will need to use -one of the atomic array classes in java.util.concurrent (provided -in Java 5.0).</p>]]></description> + + </rule> <rule key="UI_INHERITANCE_UNSAFE_GETRESOURCE"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Usage of GetResource may be unsafe if class is extended]]></name> <configKey><![CDATA[UI_INHERITANCE_UNSAFE_GETRESOURCE]]></configKey> - - <description><![CDATA[<p>Calling <code>this.getClass().getResource(...)</code> could give -results other than expected if this class is extended by a class in -another package.</p>]]></description> + + </rule> <rule key="NP_BOOLEAN_RETURN_NULL"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Method with Boolean return type returns explicit null]]></name> <configKey><![CDATA[NP_BOOLEAN_RETURN_NULL]]></configKey> - - <description><![CDATA[<p> - A method that returns either Boolean.TRUE, Boolean.FALSE or null is an accident waiting to happen. - This method can be invoked as though it returned a value of type boolean, and - the compiler will insert automatic unboxing of the Boolean value. If a null value is returned, - this will result in a NullPointerException. - </p>]]></description> + + </rule> <rule key="NP_SYNC_AND_NULL_CHECK_FIELD"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Multithreaded correctness - Synchronize and null check on the same field.]]></name> <configKey><![CDATA[NP_SYNC_AND_NULL_CHECK_FIELD]]></configKey> - - <description><![CDATA[<p>Since the field is synchronized on, it seems not likely to be null. -If it is null and then synchronized on a NullPointerException will be -thrown and the check would be pointless. Better to synchronize on -another field.</p>]]></description> + + </rule> <rule key="RpC_REPEATED_CONDITIONAL_TEST"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Repeated conditional tests]]></name> <configKey><![CDATA[RpC_REPEATED_CONDITIONAL_TEST]]></configKey> - - <description><![CDATA[<p>The code contains a conditional test is performed twice, one right after the other -(e.g., <code>x == 0 || x == 0</code>). Perhaps the second occurrence is intended to be something else -(e.g., <code>x == 0 || y == 0</code>). -</p>]]></description> + + </rule> <rule key="AM_CREATES_EMPTY_ZIP_FILE_ENTRY"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Creates an empty zip file entry]]></name> <configKey><![CDATA[AM_CREATES_EMPTY_ZIP_FILE_ENTRY]]></configKey> - - <description><![CDATA[<p>The code calls <code>putNextEntry()</code>, immediately -followed by a call to <code>closeEntry()</code>. This results -in an empty ZipFile entry. The contents of the entry -should be written to the ZipFile between the calls to -<code>putNextEntry()</code> and -<code>closeEntry()</code>.</p>]]></description> + + </rule> <rule key="AM_CREATES_EMPTY_JAR_FILE_ENTRY"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Creates an empty jar file entry]]></name> <configKey><![CDATA[AM_CREATES_EMPTY_JAR_FILE_ENTRY]]></configKey> - - <description><![CDATA[<p>The code calls <code>putNextEntry()</code>, immediately -followed by a call to <code>closeEntry()</code>. This results -in an empty JarFile entry. The contents of the entry -should be written to the JarFile between the calls to -<code>putNextEntry()</code> and -<code>closeEntry()</code>.</p>]]></description> + + </rule> <rule key="IMSE_DONT_CATCH_IMSE"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Dubious catching of IllegalMonitorStateException]]></name> <configKey><![CDATA[IMSE_DONT_CATCH_IMSE]]></configKey> - - <description><![CDATA[<p>IllegalMonitorStateException is generally only - thrown in case of a design flaw in your code (calling wait or - notify on an object you do not hold a lock on).</p>]]></description> + + </rule> <rule key="FL_MATH_USING_FLOAT_PRECISION"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Method performs math using floating point precision]]></name> <configKey><![CDATA[FL_MATH_USING_FLOAT_PRECISION]]></configKey> - - <description><![CDATA[<p> - The method performs math operations using floating point precision. - Floating point precision is very imprecise. For example, - 16777216.0f + 1.0f = 16777216.0f. Consider using double math instead.</p>]]></description> + + </rule> <rule key="CN_IDIOM"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Class implements Cloneable but does not define or use clone method]]></name> <configKey><![CDATA[CN_IDIOM]]></configKey> - - <description><![CDATA[<p> - Class implements Cloneable but does not define or - use the clone method.</p>]]></description> + + </rule> <rule key="CN_IMPLEMENTS_CLONE_BUT_NOT_CLONEABLE"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Class defines clone() but doesn't implement Cloneable]]></name> <configKey><![CDATA[CN_IMPLEMENTS_CLONE_BUT_NOT_CLONEABLE]]></configKey> - - <description><![CDATA[<p> This class defines a clone() method but the class doesn't implement Cloneable. -There are some situations in which this is OK (e.g., you want to control how subclasses -can clone themselves), but just make sure that this is what you intended. -</p>]]></description> + + </rule> <rule key="CN_IDIOM_NO_SUPER_CALL"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - clone method does not call super.clone()]]></name> <configKey><![CDATA[CN_IDIOM_NO_SUPER_CALL]]></configKey> - - <description><![CDATA[<p> This non-final class defines a clone() method that does not call super.clone(). -If this class ("<i>A</i>") is extended by a subclass ("<i>B</i>"), -and the subclass <i>B</i> calls super.clone(), then it is likely that -<i>B</i>'s clone() method will return an object of type <i>A</i>, -which violates the standard contract for clone().</p> -<p> If all clone() methods call super.clone(), then they are guaranteed -to use Object.clone(), which always returns an object of the correct type.</p>]]></description> + </rule> <rule key="NM_FUTURE_KEYWORD_USED_AS_IDENTIFIER"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Use of identifier that is a keyword in later versions of Java]]></name> <configKey><![CDATA[NM_FUTURE_KEYWORD_USED_AS_IDENTIFIER]]></configKey> - - <description><![CDATA[<p>The identifier is a word that is reserved as a keyword in later versions of Java, and your code will need to be changed -in order to compile it in later versions of Java.</p>]]></description> + + </rule> <rule key="NM_FUTURE_KEYWORD_USED_AS_MEMBER_IDENTIFIER"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Use of identifier that is a keyword in later versions of Java]]></name> <configKey><![CDATA[NM_FUTURE_KEYWORD_USED_AS_MEMBER_IDENTIFIER]]></configKey> - - <description><![CDATA[<p>This identifier is used as a keyword in later versions of Java. This code, and -any code that references this API, -will need to be changed in order to compile it in later versions of Java.</p>]]></description> + + </rule> <rule key="DE_MIGHT_DROP"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Method might drop exception]]></name> <configKey><![CDATA[DE_MIGHT_DROP]]></configKey> - - <description><![CDATA[<p> This method might drop an exception. In general, exceptions - should be handled or reported in some way, or they should be thrown - out of the method.</p>]]></description> + + </rule> <rule key="DE_MIGHT_IGNORE"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Method might ignore exception]]></name> <configKey><![CDATA[DE_MIGHT_IGNORE]]></configKey> - - <description><![CDATA[<p> This method might ignore an exception. In general, exceptions - should be handled or reported in some way, or they should be thrown - out of the method.</p>]]></description> + + </rule> <rule key="DP_DO_INSIDE_DO_PRIVILEGED"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Method invoked that should be only be invoked inside a doPrivileged block]]></name> <configKey><![CDATA[DP_DO_INSIDE_DO_PRIVILEGED]]></configKey> - - <description><![CDATA[<p> This code invokes a method that requires a security permission check. - If this code will be granted security permissions, but might be invoked by code that does not - have security permissions, then the invocation needs to occur inside a doPrivileged block.</p>]]></description> + + </rule> <rule key="DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Classloaders should only be created inside doPrivileged block]]></name> <configKey><![CDATA[DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED]]></configKey> - - <description><![CDATA[<p> This code creates a classloader, which requires a security manager. - If this code will be granted security permissions, but might be invoked by code that does not - have security permissions, then the classloader creation needs to occur inside a doPrivileged block.</p>]]></description> + + </rule> <rule key="JCIP_FIELD_ISNT_FINAL_IN_IMMUTABLE_CLASS"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Bad practice - Fields of immutable classes should be final]]></name> <configKey><![CDATA[JCIP_FIELD_ISNT_FINAL_IN_IMMUTABLE_CLASS]]></configKey> - - <description><![CDATA[<p> The class is annotated with net.jcip.annotations.Immutable, and the rules for that annotation require -that all fields are final. - .</p>]]></description> + + </rule> <rule key="DMI_THREAD_PASSED_WHERE_RUNNABLE_EXPECTED"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Dodgy - Thread passed where Runnable expected]]></name> <configKey><![CDATA[DMI_THREAD_PASSED_WHERE_RUNNABLE_EXPECTED]]></configKey> - - <description><![CDATA[<p> A Thread object is passed as a parameter to a method where -a Runnable is expected. This is rather unusual, and may indicate a logic error -or cause unexpected behavior. - </p>]]></description> + + </rule> <rule key="DMI_COLLECTION_OF_URLS"> -<priority>BLOCKER</priority> + <priority>BLOCKER</priority> <name><![CDATA[Performance - Maps and sets of URLs can be performance hogs]]></name> <configKey><![CDATA[DMI_COLLECTION_OF_URLS]]></configKey> - - <description><![CDATA[<p> This method or field is or uses a Map or Set of URLs. Since both the equals and hashCode -method of URL perform domain name resolution, this can result in a big performance hit. -See <a href="http://michaelscharf.blogspot.com/2006/11/javaneturlequals-and-hashcode-make.html">http://michaelscharf.blogspot.com/2006/11/javaneturlequals-and-hashcode-make.html</a> for more information. -Consider using <code>java.net.URI</code> instead. - </p>]]></description> + + </rule> <rule key="DMI_BLOCKING_METHODS_ON_URL"> -<priority>BLOCKER</priority> + <priority>BLOCKER</priority> <name><![CDATA[Performance - The equals and hashCode methods of URL are blocking]]></name> <configKey><![CDATA[DMI_BLOCKING_METHODS_ON_URL]]></configKey> - - <description><![CDATA[<p> The equals and hashCode -method of URL perform domain name resolution, this can result in a big performance hit. -See <a href="http://michaelscharf.blogspot.com/2006/11/javaneturlequals-and-hashcode-make.html">http://michaelscharf.blogspot.com/2006/11/javaneturlequals-and-hashcode-make.html</a> for more information. -Consider using <code>java.net.URI</code> instead. - </p>]]></description> + + </rule> <rule key="DMI_ANNOTATION_IS_NOT_VISIBLE_TO_REFLECTION"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name> <![CDATA[Correctness - Can't use reflection to check for presence of annotation without runtime retention]]></name> <configKey><![CDATA[DMI_ANNOTATION_IS_NOT_VISIBLE_TO_REFLECTION]]></configKey> - - <description><![CDATA[<p> Unless an annotation has itself been annotated with @Retention(RetentionPolicy.RUNTIME), the annotation can't be observed using reflection -(e.g., by using the isAnnotationPresent method). - .</p>]]></description> + + </rule> <rule key="DM_EXIT"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Method invokes System.exit(...)]]></name> <configKey><![CDATA[DM_EXIT]]></configKey> - - <description><![CDATA[<p> Invoking System.exit shuts down the entire Java virtual machine. This - should only been done when it is appropriate. Such calls make it - hard or impossible for your code to be invoked by other code. - Consider throwing a RuntimeException instead.</p>]]></description> + + </rule> <rule key="DM_RUN_FINALIZERS_ON_EXIT"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Method invokes dangerous method runFinalizersOnExit]]></name> <configKey><![CDATA[DM_RUN_FINALIZERS_ON_EXIT]]></configKey> - - <description><![CDATA[<p> <em>Never call System.runFinalizersOnExit -or Runtime.runFinalizersOnExit for any reason: they are among the most -dangerous methods in the Java libraries.</em> -- Joshua Bloch</p>]]></description> + + </rule> <rule key="DM_STRING_CTOR"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Performance - Method invokes inefficient new String(String) constructor]]></name> <configKey><![CDATA[DM_STRING_CTOR]]></configKey> - - <description><![CDATA[<p> Using the <code>java.lang.String(String)</code> constructor wastes memory - because the object so constructed will be functionally indistinguishable - from the <code>String</code> passed as a parameter. Just use the - argument <code>String</code> directly.</p>]]></description> + + </rule> <rule key="DM_STRING_VOID_CTOR"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Performance - Method invokes inefficient new String() constructor]]></name> <configKey><![CDATA[DM_STRING_VOID_CTOR]]></configKey> - - <description><![CDATA[<p> Creating a new <code>java.lang.String</code> object using the - no-argument constructor wastes memory because the object so created will - be functionally indistinguishable from the empty string constant - <code>""</code>. Java guarantees that identical string constants - will be represented by the same <code>String</code> object. Therefore, - you should just use the empty string constant directly.</p>]]></description> + + </rule> <rule key="DM_STRING_TOSTRING"> -<priority>INFO</priority> + <priority>INFO</priority> <name><![CDATA[Performance - Method invokes toString() method on a String]]></name> <configKey><![CDATA[DM_STRING_TOSTRING]]></configKey> - - <description><![CDATA[<p> Calling <code>String.toString()</code> is just a redundant operation. - Just use the String.</p>]]></description> + + </rule> <rule key="DM_GC"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Performance - Explicit garbage collection; extremely dubious except in benchmarking code]]></name> <configKey><![CDATA[DM_GC]]></configKey> - - <description><![CDATA[<p> Code explicitly invokes garbage collection. - Except for specific use in benchmarking, this is very dubious.</p> - <p>In the past, situations where people have explicitly invoked - the garbage collector in routines such as close or finalize methods - has led to huge performance black holes. Garbage collection - can be expensive. Any situation that forces hundreds or thousands - of garbage collections will bring the machine to a crawl.</p>]]></description> + + </rule> <rule key="DM_BOOLEAN_CTOR"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name> <![CDATA[Performance - Method invokes inefficient Boolean constructor; use Boolean.valueOf(...) instead]]></name> <configKey><![CDATA[DM_BOOLEAN_CTOR]]></configKey> - - <description><![CDATA[<p> Creating new instances of <code>java.lang.Boolean</code> wastes - memory, since <code>Boolean</code> objects are immutable and there are - only two useful values of this type. Use the <code>Boolean.valueOf()</code> - method (or Java 1.5 autoboxing) to create <code>Boolean</code> objects instead.</p>]]></description> + + </rule> <rule key="DM_NUMBER_CTOR"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Performance - Method invokes inefficient Number constructor; use static valueOf instead]]></name> <configKey><![CDATA[DM_NUMBER_CTOR]]></configKey> - - <description><![CDATA[<p> - Using <code>new Integer(int)</code> is guaranteed to always result in a new object whereas - <code>Integer.valueOf(int)</code> allows caching of values to be done by the compiler, class library, or JVM. - Using of cached values avoids object allocation and the code will be faster. - </p> - <p> - Values between -128 and 127 are guaranteed to have corresponding cached instances - and using <code>valueOf</code> is approximately 3.5 times faster than using constructor. - For values outside the constant range the performance of both styles is the same. - </p> - <p> - Unless the class must be compatible with JVMs predating Java 1.5, - use either autoboxing or the <code>valueOf()</code> method when creating instances of - <code>Long</code>, <code>Integer</code>, <code>Short</code>, <code>Character</code>, and <code>Byte</code>. - </p>]]></description> + + </rule> <rule key="DM_FP_NUMBER_CTOR"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name> <![CDATA[Performance - Method invokes inefficient floating-point Number constructor; use static valueOf instead]]></name> <configKey><![CDATA[DM_FP_NUMBER_CTOR]]></configKey> - - <description><![CDATA[<p> - Using <code>new Double(double)</code> is guaranteed to always result in a new object whereas - <code>Double.valueOf(double)</code> allows caching of values to be done by the compiler, class library, or JVM. - Using of cached values avoids object allocation and the code will be faster. - </p> - <p> - Unless the class must be compatible with JVMs predating Java 1.5, - use either autoboxing or the <code>valueOf()</code> method when creating instances of <code>Double</code> and <code>Float</code>. - </p>]]></description> + + </rule> <rule key="DM_CONVERT_CASE"> -<priority>INFO</priority> + <priority>INFO</priority> <name><![CDATA[Internationalization - Consider using Locale parameterized version of invoked method]]></name> <configKey><![CDATA[DM_CONVERT_CASE]]></configKey> - - <description><![CDATA[<p> A String is being converted to upper or lowercase, using the platform's default encoding. This may - result in improper conversions when used with international characters. Use the </p> - <table><tr><td>String.toUpperCase( Locale l )</td></tr><tr><td>String.toLowerCase( Locale l )</td></tr></table> - <p>versions instead.</p>]]></description> + + </rule> <rule key="BX_UNBOXED_AND_COERCED_FOR_TERNARY_OPERATOR"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Primitive value is unboxed and coerced for ternary operator]]></name> <configKey><![CDATA[BX_UNBOXED_AND_COERCED_FOR_TERNARY_OPERATOR]]></configKey> - - <description><![CDATA[<p>A wrapped primitive value is unboxed and converted to another primitive type as part of the -evaluation of a conditional ternary operator (the <code> b ? e1 : e2</code> operator). The -semantics of Java mandate that if <code>e1</code> and <code>e2</code> are wrapped -numeric values, the values are unboxed and converted/coerced to their common type (e.g, -if <code>e1</code> is of type <code>Integer</code> -and <code>e2</code> is of type <code>Float</code>, then <code>e1</code> is unboxed, -converted to a floating point value, and boxed. See JLS Section 15.25. -</p>]]></description> + + </rule> <rule key="BX_BOXING_IMMEDIATELY_UNBOXED"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Performance - Primitive value is boxed and then immediately unboxed]]></name> <configKey><![CDATA[BX_BOXING_IMMEDIATELY_UNBOXED]]></configKey> - - <description><![CDATA[<p>A primitive is boxed, and then immediately unboxed. This probably is due to a manual - boxing in a place where an unboxed value is required, thus forcing the compiler -to immediately undo the work of the boxing. -</p>]]></description> + + </rule> <rule key="BX_BOXING_IMMEDIATELY_UNBOXED_TO_PERFORM_COERCION"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Performance - Primitive value is boxed then unboxed to perform primitive coercion]]></name> <configKey><![CDATA[BX_BOXING_IMMEDIATELY_UNBOXED_TO_PERFORM_COERCION]]></configKey> - - <description><![CDATA[<p>A primitive boxed value constructed and then immediately converted into a different primitive type -(e.g., <code>new Double(d).intValue()</code>). Just perform direct primitive coercion (e.g., <code>(int) d</code>).</p>]]></description> + + </rule> <rule key="DM_BOXED_PRIMITIVE_TOSTRING"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Performance - Method allocates a boxed primitive just to call toString]]></name> <configKey><![CDATA[DM_BOXED_PRIMITIVE_TOSTRING]]></configKey> - - <description><![CDATA[<p>A boxed primitive is allocated just to call toString(). It is more effective to just use the static - form of toString which takes the primitive value. So,</p> - <table> - <tr><th>Replace...</th><th>With this...</th></tr> - <tr><td>new Integer(1).toString()</td><td>Integer.toString(1)</td></tr> - <tr><td>new Long(1).toString()</td><td>Long.toString(1)</td></tr> - <tr><td>new Float(1.0).toString()</td><td>Float.toString(1.0)</td></tr> - <tr><td>new Double(1.0).toString()</td><td>Double.toString(1.0)</td></tr> - <tr><td>new Byte(1).toString()</td><td>Byte.toString(1)</td></tr> - <tr><td>new Short(1).toString()</td><td>Short.toString(1)</td></tr> - <tr><td>new Boolean(true).toString()</td><td>Boolean.toString(true)</td></tr> - </table>]]></description> + + </rule> <rule key="DM_NEW_FOR_GETCLASS"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Performance - Method allocates an object, only to get the class object]]></name> <configKey><![CDATA[DM_NEW_FOR_GETCLASS]]></configKey> - - <description><![CDATA[<p>This method allocates an object just to call getClass() on it, in order to - retrieve the Class object for it. It is simpler to just access the .class property of the class.</p>]]></description> + + </rule> <rule key="DM_MONITOR_WAIT_ON_CONDITION"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Multithreaded correctness - Monitor wait() called on Condition]]></name> <configKey><![CDATA[DM_MONITOR_WAIT_ON_CONDITION]]></configKey> - - <description><![CDATA[<p> - This method calls <code>wait()</code> on a - <code>java.util.concurrent.locks.Condition</code> object. - Waiting for a <code>Condition</code> should be done using one of the <code>await()</code> - methods defined by the <code>Condition</code> interface. - </p>]]></description> + + </rule> <rule key="RV_01_TO_INT"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Random value from 0 to 1 is coerced to the integer 0]]></name> <configKey><![CDATA[RV_01_TO_INT]]></configKey> - - <description><![CDATA[<p>A random value from 0 to 1 is being coerced to the integer value 0. You probably -want to multiple the random value by something else before coercing it to an integer, or use the <code>Random.nextInt(n)</code> method. -</p>]]></description> + + </rule> <rule key="DM_NEXTINT_VIA_NEXTDOUBLE"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name> <![CDATA[Performance - Use the nextInt method of Random rather than nextDouble to generate a random integer]]></name> <configKey><![CDATA[DM_NEXTINT_VIA_NEXTDOUBLE]]></configKey> - - <description><![CDATA[<p>If <code>r</code> is a <code>java.util.Random</code>, you can generate a random number from <code>0</code> to <code>n-1</code> -using <code>r.nextInt(n)</code>, rather than using <code>(int)(r.nextDouble() * n)</code>. -</p>]]></description> + + </rule> <rule key="SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Security - Nonconstant string passed to execute method on an SQL statement]]></name> <configKey><![CDATA[SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE]]></configKey> - - <description><![CDATA[<p>The method invokes the execute method on an SQL statement with a String that seems -to be dynamically generated. Consider using -a prepared statement instead. It is more efficient and less vulnerable to -SQL injection attacks. -</p>]]></description> + + </rule> <rule key="SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Security - A prepared statement is generated from a nonconstant String]]></name> <configKey><![CDATA[SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING]]></configKey> - - <description><![CDATA[<p>The code creates an SQL prepared statement from a nonconstant String. -If unchecked, tainted data from a user is used in building this String, SQL injection could -be used to make the prepared statement do something unexpected and undesirable. -</p>]]></description> + + </rule> <rule key="DM_USELESS_THREAD"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Multithreaded correctness - A thread was created using the default empty run method]]></name> <configKey><![CDATA[DM_USELESS_THREAD]]></configKey> - - <description><![CDATA[<p>This method creates a thread without specifying a run method either by deriving from the Thread class, or - by passing a Runnable object. This thread, then, does nothing but waste time. -</p>]]></description> + + </rule> <rule key="DC_DOUBLECHECK"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Multithreaded correctness - Possible double check of field]]></name> <configKey><![CDATA[DC_DOUBLECHECK]]></configKey> - - <description><![CDATA[<p> This method may contain an instance of double-checked locking. - This idiom is not correct according to the semantics of the Java memory - model. For more information, see the web page - <a href="http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html" - >http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html</a>.</p>]]></description> + + </rule> <rule key="FI_FINALIZER_NULLS_FIELDS"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Finalizer nulls fields]]></name> <configKey><![CDATA[FI_FINALIZER_NULLS_FIELDS]]></configKey> - - <description><![CDATA[<p> This finalizer nulls out fields. This is usually an error, as it does not aid garbage collection, - and the object is going to be garbage collected anyway.]]></description> + + </rule> <rule key="FI_FINALIZER_ONLY_NULLS_FIELDS"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Finalizer only nulls fields]]></name> <configKey><![CDATA[FI_FINALIZER_ONLY_NULLS_FIELDS]]></configKey> - - <description><![CDATA[<p> This finalizer does nothing except null out fields. This is completely pointless, and requires that -the object be garbage collected, finalized, and then garbage collected again. You should just remove the finalize -method.]]></description> + + </rule> <rule key="FI_PUBLIC_SHOULD_BE_PROTECTED"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Malicious code vulnerability - Finalizer should be protected, not public]]></name> <configKey><![CDATA[FI_PUBLIC_SHOULD_BE_PROTECTED]]></configKey> - - <description><![CDATA[<p> A class's <code>finalize()</code> method should have protected access, - not public.</p>]]></description> + + </rule> <rule key="FI_EMPTY"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Empty finalizer should be deleted]]></name> <configKey><![CDATA[FI_EMPTY]]></configKey> - - <description><![CDATA[<p> Empty <code>finalize()</code> methods are useless, so they should - be deleted.</p>]]></description> + + </rule> <rule key="FI_NULLIFY_SUPER"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Finalizer nullifies superclass finalizer]]></name> <configKey><![CDATA[FI_NULLIFY_SUPER]]></configKey> - - <description><![CDATA[<p> This empty <code>finalize()</code> method explicitly negates the - effect of any finalizer defined by its superclass. Any finalizer - actions defined for the superclass will not be performed. - Unless this is intended, delete this method.</p>]]></description> + + </rule> <rule key="FI_USELESS"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Bad practice - Finalizer does nothing but call superclass finalizer]]></name> <configKey><![CDATA[FI_USELESS]]></configKey> - - <description><![CDATA[<p> The only thing this <code>finalize()</code> method does is call - the superclass's <code>finalize()</code> method, making it - redundant. Delete it.</p>]]></description> + + </rule> <rule key="FI_MISSING_SUPER_CALL"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Finalizer does not call superclass finalizer]]></name> <configKey><![CDATA[FI_MISSING_SUPER_CALL]]></configKey> - - <description><![CDATA[<p> This <code>finalize()</code> method does not make a call to its - superclass's <code>finalize()</code> method. So, any finalizer - actions defined for the superclass will not be performed. - Add a call to <code>super.finalize()</code>.</p>]]></description> + + </rule> <rule key="FI_EXPLICIT_INVOCATION"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Explicit invocation of finalizer]]></name> <configKey><![CDATA[FI_EXPLICIT_INVOCATION]]></configKey> - - <description><![CDATA[<p> This method contains an explicit invocation of the <code>finalize()</code> - method on an object. Because finalizer methods are supposed to be - executed once, and only by the VM, this is a bad idea.</p> -<p>If a connected set of objects beings finalizable, then the VM will invoke the -finalize method on all the finalizable object, possibly at the same time in different threads. -Thus, it is a particularly bad idea, in the finalize method for a class X, invoke finalize -on objects referenced by X, because they may already be getting finalized in a separate thread.]]></description> + + </rule> <rule key="EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Equals checks for noncompatible operand]]></name> <configKey><![CDATA[EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS]]></configKey> - - <description><![CDATA[<p> This equals method is checking to see if the argument is some incompatible type -(i.e., a class that is neither a supertype nor subtype of the class that defines -the equals method). For example, the Foo class might have an equals method -that looks like: - -<p><code><pre> -public boolean equals(Object o) { - if (o instanceof Foo) - return name.equals(((Foo)o).name); - else if (o instanceof String) - return name.equals(o); - else return false; -</pre></code></p> - -<p>This is considered bad practice, as it makes it very hard to implement an equals method that -is symmetric and transitive. Without those properties, very unexpected behavoirs are possible. -</p>]]></description> + + </rule> <rule key="EQ_DONT_DEFINE_EQUALS_FOR_ENUM"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Covariant equals() method defined for enum]]></name> <configKey><![CDATA[EQ_DONT_DEFINE_EQUALS_FOR_ENUM]]></configKey> - - <description><![CDATA[<p> This class defines an enumeration, and equality on enumerations are defined -using object identity. Defining a covariant equals method for an enumeration -value is exceptionally bad practice, since it would likely result -in having two different enumeration values that compare as equals using -the covariant enum method, and as not equal when compared normally. -Don't do it. -</p>]]></description> + + </rule> <rule key="EQ_SELF_USE_OBJECT"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Covariant equals() method defined, Object.equals(Object) inherited]]></name> <configKey><![CDATA[EQ_SELF_USE_OBJECT]]></configKey> - - <description><![CDATA[<p> This class defines a covariant version of the <code>equals()</code> - method, but inherits the normal <code>equals(Object)</code> method - defined in the base <code>java.lang.Object</code> class. - The class should probably define a <code>boolean equals(Object)</code> method. - </p>]]></description> + + </rule> <rule key="EQ_OTHER_USE_OBJECT"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - equals() method defined that doesn't override Object.equals(Object)]]></name> <configKey><![CDATA[EQ_OTHER_USE_OBJECT]]></configKey> - - <description><![CDATA[<p> This class defines an <code>equals()</code> - method, that doesn't override the normal <code>equals(Object)</code> method - defined in the base <code>java.lang.Object</code> class. - The class should probably define a <code>boolean equals(Object)</code> method. - </p>]]></description> + + </rule> <rule key="EQ_OTHER_NO_OBJECT"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - equals() method defined that doesn't override equals(Object)]]></name> <configKey><![CDATA[EQ_OTHER_NO_OBJECT]]></configKey> - - <description><![CDATA[<p> This class defines an <code>equals()</code> - method, that doesn't override the normal <code>equals(Object)</code> method - defined in the base <code>java.lang.Object</code> class. Instead, it - inherits an <code>equals(Object)</code> method from a superclass. - The class should probably define a <code>boolean equals(Object)</code> method. - </p>]]></description> + + </rule> <!-- warning : http://sourceforge.net/tracker/?func=detail&aid=2786054&group_id=96405&atid=614693 --> <rule key="EQ_DOESNT_OVERRIDE_EQUALS"> <name><![CDATA[Dodgy - Class doesn't override equals in superclass]]></name> <configKey><![CDATA[EQ_DOESNT_OVERRIDE_EQUALS]]></configKey> - - <description><![CDATA[<p> This class extends a class that defines an equals method and adds fields, but doesn't -define an equals method itself. Thus, equality on instances of this class will -ignore the identity of the subclass and the added fields. Be sure this is what is intended, -and that you don't need to override the equals method. Even if you don't need to override -the equals method, consider overriding it anyway to document the fact -that the equals method for the subclass just return the result of -invoking super.equals(o). - </p>]]></description> + + </rule> <rule key="EQ_SELF_NO_OBJECT"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Covariant equals() method defined]]></name> <configKey><![CDATA[EQ_SELF_NO_OBJECT]]></configKey> - - <description><![CDATA[<p> This class defines a covariant version of <code>equals()</code>. - To correctly override the <code>equals()</code> method in - <code>java.lang.Object</code>, the parameter of <code>equals()</code> - must have type <code>java.lang.Object</code>.</p>]]></description> + + </rule> <rule key="EQ_OVERRIDING_EQUALS_NOT_SYMMETRIC"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - equals method overrides equals in superclass and may not be symmetric]]></name> <configKey><![CDATA[EQ_OVERRIDING_EQUALS_NOT_SYMMETRIC]]></configKey> - - <description><![CDATA[<p> This class defines an equals method that overrides an equals method in a superclass. Both equals methods -methods use <code>instanceof</code> in the determination of whether two objects are equal. This is fraught with peril, -since it is important that the equals method is symmetrical (in other words, <code>a.equals(b) == b.equals(a)</code>). -If B is a subtype of A, and A's equals method checks that the argument is an instanceof A, and B's equals method -checks that the argument is an instanceof B, it is quite likely that the equivalence relation defined by these -methods is not symmetric. -</p>]]></description> + + </rule> <rule key="EQ_GETCLASS_AND_CLASS_CONSTANT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - equals method fails for subtypes]]></name> <configKey><![CDATA[EQ_GETCLASS_AND_CLASS_CONSTANT]]></configKey> - - <description><![CDATA[<p> This class has an equals method that will be broken if it is inherited by subclasses. -It compares a class literal with the class of the argument (e.g., in class <code>Foo</code> -it might check if <code>Foo.class == o.getClass()</code>). -It is better to check if <code>this.getClass() == o.getClass()</code>. -</p>]]></description> + + </rule> <rule key="EQ_UNUSUAL"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Dodgy - Unusual equals method ]]></name> <configKey><![CDATA[EQ_UNUSUAL]]></configKey> - - <description><![CDATA[<p> This class doesn't do any of the patterns we recognize for checking that the type of the argument -is compatible with the type of the <code>this</code> object. There might not be anything wrong with -this code, but it is worth reviewing. -</p>]]></description> + + </rule> <rule key="EQ_COMPARING_CLASS_NAMES"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - equals method compares class names rather than class objects]]></name> <configKey><![CDATA[EQ_COMPARING_CLASS_NAMES]]></configKey> - - <description><![CDATA[<p> This method checks to see if two objects are the same class by checking to see if the names -of their classes are equal. You can have different classes with the same name if they are loaded by -different class loaders. Just check to see if the class objects are the same. -</p>]]></description> + + </rule> <rule key="EQ_ALWAYS_TRUE"> -<priority>BLOCKER</priority> + <priority>BLOCKER</priority> <name><![CDATA[Correctness - equals method always returns true]]></name> <configKey><![CDATA[EQ_ALWAYS_TRUE]]></configKey> - - <description><![CDATA[<p> This class defines an equals method that always returns true. This is imaginative, but not very smart. -Plus, it means that the equals method is not symmetric. -</p>]]></description> + + </rule> <rule key="EQ_ALWAYS_FALSE"> -<priority>BLOCKER</priority> + <priority>BLOCKER</priority> <name><![CDATA[Correctness - equals method always returns false]]></name> <configKey><![CDATA[EQ_ALWAYS_FALSE]]></configKey> - - <description><![CDATA[<p> This class defines an equals method that always returns false. This means that an object is not equal to itself, and it is impossible to create useful Maps or Sets of this class. More fundamentally, it means -that equals is not reflexive, one of the requirements of the equals method.</p> -<p>The likely intended semantics are object identity: that an object is equal to itself. This is the behavior inherited from class <code>Object</code>. If you need to override an equals inherited from a different -superclass, you can use use: -<pre> -public boolean equals(Object o) { return this == o; } -</pre> -</p>]]></description> + + </rule> <rule key="HSC_HUGE_SHARED_STRING_CONSTANT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Performance - Huge string constants is duplicated across multiple class files]]></name> <configKey><![CDATA[HSC_HUGE_SHARED_STRING_CONSTANT]]></configKey> - - <description><![CDATA[<p> - A large String constant is duplicated across multiple class files. - This is likely because a final field is initialized to a String constant, and the Java language - mandates that all references to a final field from other classes be inlined into -that classfile. See <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6447475">JDK bug 6447475</a> - for a description of an occurrence of this bug in the JDK and how resolving it reduced - the size of the JDK by 1 megabyte. -</p>]]></description> + + </rule> <rule key="NP_ARGUMENT_MIGHT_BE_NULL"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Method does not check for null argument]]></name> <configKey><![CDATA[NP_ARGUMENT_MIGHT_BE_NULL]]></configKey> - - <description><![CDATA[<p> - A parameter to this method has been identified as a value that should - always be checked to see whether or not it is null, but it is being dereferenced - without a preceding null check. - </p>]]></description> + + </rule> <rule key="NP_EQUALS_SHOULD_HANDLE_NULL_ARGUMENT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - equals() method does not check for null argument]]></name> <configKey><![CDATA[NP_EQUALS_SHOULD_HANDLE_NULL_ARGUMENT]]></configKey> - - <description><![CDATA[<p> - This implementation of equals(Object) violates the contract defined - by java.lang.Object.equals() because it does not check for null - being passed as the argument. All equals() methods should return - false if passed a null value. - </p>]]></description> + + </rule> <rule key="CO_SELF_NO_OBJECT"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Covariant compareTo() method defined]]></name> <configKey><![CDATA[CO_SELF_NO_OBJECT]]></configKey> - - <description><![CDATA[<p> This class defines a covariant version of <code>compareTo()</code>. - To correctly override the <code>compareTo()</code> method in the - <code>Comparable</code> interface, the parameter of <code>compareTo()</code> - must have type <code>java.lang.Object</code>.</p>]]></description> + + </rule> <rule key="HE_SIGNATURE_DECLARES_HASHING_OF_UNHASHABLE_CLASS"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Signature declares use of unhashable class in hashed construct]]></name> <configKey><![CDATA[HE_SIGNATURE_DECLARES_HASHING_OF_UNHASHABLE_CLASS]]></configKey> - - <description><![CDATA[<p> A method, field or class declares a generic signature where a non-hashable class -is used in context where a hashable class is required. -A class that declares an equals method but inherits a hashCode() method -from Object is unhashable, since it doesn't fulfill the requirement that -equal objects have equal hashCodes. -</p>]]></description> + + </rule> <rule key="HE_USE_OF_UNHASHABLE_CLASS"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Use of class without a hashCode() method in a hashed data structure]]></name> <configKey><![CDATA[HE_USE_OF_UNHASHABLE_CLASS]]></configKey> - - <description><![CDATA[<p> A class defines an equals(Object) method but not a hashCode() method, -and thus doesn't fulfill the requirement that equal objects have equal hashCodes. -An instance of this class is used in a hash data structure, making the need to -fix this problem of highest importance.]]></description> + + </rule> <rule key="HE_HASHCODE_USE_OBJECT_EQUALS"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Class defines hashCode() and uses Object.equals()]]></name> <configKey><![CDATA[HE_HASHCODE_USE_OBJECT_EQUALS]]></configKey> - - <description><![CDATA[<p> This class defines a <code>hashCode()</code> method but inherits its - <code>equals()</code> method from <code>java.lang.Object</code> - (which defines equality by comparing object references). Although - this will probably satisfy the contract that equal objects must have - equal hashcodes, it is probably not what was intended by overriding - the <code>hashCode()</code> method. (Overriding <code>hashCode()</code> - implies that the object's identity is based on criteria more complicated - than simple reference equality.)</p> -<p>If you don't think instances of this class will ever be inserted into a HashMap/HashTable, -the recommended <code>hashCode</code> implementation to use is:</p> -<p><pre>public int hashCode() { - assert false : "hashCode not designed"; - return 42; // any arbitrary constant will do - }</pre></p>]]></description> + + </rule> <rule key="EQ_COMPARETO_USE_OBJECT_EQUALS"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Class defines compareTo(...) and uses Object.equals()]]></name> <configKey><![CDATA[EQ_COMPARETO_USE_OBJECT_EQUALS]]></configKey> - - <description><![CDATA[<p> This class defines a <code>compareTo(...)</code> method but inherits its - <code>equals()</code> method from <code>java.lang.Object</code>. - Generally, the value of compareTo should return zero if and only if - equals returns true. If this is violated, weird and unpredictable - failures will occur in classes such as PriorityQueue. - In Java 5 the PriorityQueue.remove method uses the compareTo method, - while in Java 6 it uses the equals method. - -<p>From the JavaDoc for the compareTo method in the Comparable interface: -<blockquote> -It is strongly recommended, but not strictly required that <code>(x.compareTo(y)==0) == (x.equals(y))</code>. -Generally speaking, any class that implements the Comparable interface and violates this condition -should clearly indicate this fact. The recommended language -is "Note: this class has a natural ordering that is inconsistent with equals." -</blockquote>]]></description> + + </rule> <rule key="HE_HASHCODE_NO_EQUALS"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Class defines hashCode() but not equals()]]></name> <configKey><![CDATA[HE_HASHCODE_NO_EQUALS]]></configKey> - - <description><![CDATA[<p> This class defines a <code>hashCode()</code> method but not an - <code>equals()</code> method. Therefore, the class may - violate the invariant that equal objects must have equal hashcodes.</p>]]></description> + + </rule> <rule key="HE_EQUALS_USE_HASHCODE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Class defines equals() and uses Object.hashCode()]]></name> <configKey><![CDATA[HE_EQUALS_USE_HASHCODE]]></configKey> - - <description><![CDATA[<p> This class overrides <code>equals(Object)</code>, but does not - override <code>hashCode()</code>, and inherits the implementation of - <code>hashCode()</code> from <code>java.lang.Object</code> (which returns - the identity hash code, an arbitrary value assigned to the object - by the VM). Therefore, the class is very likely to violate the - invariant that equal objects must have equal hashcodes.</p> - -<p>If you don't think instances of this class will ever be inserted into a HashMap/HashTable, -the recommended <code>hashCode</code> implementation to use is:</p> -<pre>public int hashCode() { - assert false : "hashCode not designed"; - return 42; // any arbitrary constant will do - }</pre>]]></description> + + </rule> <rule key="HE_INHERITS_EQUALS_USE_HASHCODE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Class inherits equals() and uses Object.hashCode()]]></name> <configKey><![CDATA[HE_INHERITS_EQUALS_USE_HASHCODE]]></configKey> - - <description><![CDATA[<p> This class inherits <code>equals(Object)</code> from an abstract - superclass, and <code>hashCode()</code> from -<code>java.lang.Object</code> (which returns - the identity hash code, an arbitrary value assigned to the object - by the VM). Therefore, the class is very likely to violate the - invariant that equal objects must have equal hashcodes.</p> - - <p>If you don't want to define a hashCode method, and/or don't - believe the object will ever be put into a HashMap/Hashtable, - define the <code>hashCode()</code> method - to throw <code>UnsupportedOperationException</code>.</p>]]></description> + + </rule> <rule key="HE_EQUALS_NO_HASHCODE"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Class defines equals() but not hashCode()]]></name> <configKey><![CDATA[HE_EQUALS_NO_HASHCODE]]></configKey> - - <description><![CDATA[<p> This class overrides <code>equals(Object)</code>, but does not - override <code>hashCode()</code>. Therefore, the class may violate the - invariant that equal objects must have equal hashcodes.</p>]]></description> + + </rule> <rule key="EQ_ABSTRACT_SELF"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Abstract class defines covariant equals() method]]></name> <configKey><![CDATA[EQ_ABSTRACT_SELF]]></configKey> - - <description><![CDATA[<p> This class defines a covariant version of <code>equals()</code>. - To correctly override the <code>equals()</code> method in - <code>java.lang.Object</code>, the parameter of <code>equals()</code> - must have type <code>java.lang.Object</code>.</p>]]></description> + + </rule> <rule key="ES_COMPARING_STRINGS_WITH_EQ"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Comparison of String objects using == or !=]]></name> <configKey><![CDATA[ES_COMPARING_STRINGS_WITH_EQ]]></configKey> - - <description><![CDATA[<p>This code compares <code>java.lang.String</code> objects for reference -equality using the == or != operators. -Unless both strings are either constants in a source file, or have been -interned using the <code>String.intern()</code> method, the same string -value may be represented by two different String objects. Consider -using the <code>equals(Object)</code> method instead.</p>]]></description> + + </rule> <rule key="ES_COMPARING_PARAMETER_STRING_WITH_EQ"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Comparison of String parameter using == or !=]]></name> <configKey><![CDATA[ES_COMPARING_PARAMETER_STRING_WITH_EQ]]></configKey> - - <description><![CDATA[<p>This code compares a <code>java.lang.String</code> parameter for reference -equality using the == or != operators. Requiring callers to -pass only String constants or interned strings to a method is unnecessarily -fragile, and rarely leads to measurable performance gains. Consider -using the <code>equals(Object)</code> method instead.</p>]]></description> + + </rule> <rule key="CO_ABSTRACT_SELF"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Abstract class defines covariant compareTo() method]]></name> <configKey><![CDATA[CO_ABSTRACT_SELF]]></configKey> - - <description><![CDATA[<p> This class defines a covariant version of <code>compareTo()</code>. - To correctly override the <code>compareTo()</code> method in the - <code>Comparable</code> interface, the parameter of <code>compareTo()</code> - must have type <code>java.lang.Object</code>.</p>]]></description> + + </rule> <rule key="IS_FIELD_NOT_GUARDED"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Field not guarded against concurrent access]]></name> <configKey><![CDATA[IS_FIELD_NOT_GUARDED]]></configKey> - - <description><![CDATA[<p> This field is annotated with net.jcip.annotations.GuardedBy, -but can be accessed in a way that seems to violate the annotation.</p>]]></description> + + </rule> <rule key="MSF_MUTABLE_SERVLET_FIELD"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Multithreaded correctness - Mutable servlet field]]></name> <configKey><![CDATA[MSF_MUTABLE_SERVLET_FIELD]]></configKey> - - <description><![CDATA[<p>A web server generally only creates one instance of servlet or jsp class (i.e., treats -the class as a Singleton), -and will -have multiple threads invoke methods on that instance to service multiple -simultaneous requests. -Thus, having a mutable instance field generally creates race conditions.]]></description> + + </rule> <rule key="IS2_INCONSISTENT_SYNC"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Inconsistent synchronization]]></name> <configKey><![CDATA[IS2_INCONSISTENT_SYNC]]></configKey> - - <description><![CDATA[<p> The fields of this class appear to be accessed inconsistently with respect - to synchronization. This bug report indicates that the bug pattern detector - judged that - </p> - <ol> - <li> The class contains a mix of locked and unlocked accesses,</li> - <li> At least one locked access was performed by one of the class's own methods, and</li> - <li> The number of unsynchronized field accesses (reads and writes) was no more than - one third of all accesses, with writes being weighed twice as high as reads</li> - </ol> - - <p> A typical bug matching this bug pattern is forgetting to synchronize - one of the methods in a class that is intended to be thread-safe.</p> - - <p> You can select the nodes labeled "Unsynchronized access" to show the - code locations where the detector believed that a field was accessed - without synchronization.</p> - - <p> Note that there are various sources of inaccuracy in this detector; - for example, the detector cannot statically detect all situations in which - a lock is held. Also, even when the detector is accurate in - distinguishing locked vs. unlocked accesses, the code in question may still - be correct.</p>]]></description> + + </rule> <rule key="NN_NAKED_NOTIFY"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Naked notify]]></name> <configKey><![CDATA[NN_NAKED_NOTIFY]]></configKey> - - <description><![CDATA[<p> A call to <code>notify()</code> or <code>notifyAll()</code> - was made without any (apparent) accompanying - modification to mutable object state. In general, calling a notify - method on a monitor is done because some condition another thread is - waiting for has become true. However, for the condition to be meaningful, - it must involve a heap object that is visible to both threads.</p> - - <p> This bug does not necessarily indicate an error, since the change to - mutable object state may have taken place in a method which then called - the method containing the notification.</p>]]></description> + + </rule> <rule key="MS_EXPOSE_REP"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name> <![CDATA[Malicious code vulnerability - Public static method may expose internal representation by returning array]]></name> <configKey><![CDATA[MS_EXPOSE_REP]]></configKey> - - <description><![CDATA[<p> A public static method returns a reference to - an array that is part of the static state of the class. - Any code that calls this method can freely modify - the underlying array. - One fix is to return a copy of the array.</p>]]></description> + + </rule> <rule key="EI_EXPOSE_REP"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name> <![CDATA[Malicious code vulnerability - May expose internal representation by returning reference to mutable object]]></name> <configKey><![CDATA[EI_EXPOSE_REP]]></configKey> - - <description><![CDATA[<p> Returning a reference to a mutable object value stored in one of the object's fields - exposes the internal representation of the object. - If instances - are accessed by untrusted code, and unchecked changes to - the mutable object would compromise security or other - important properties, you will need to do something different. - Returning a new copy of the object is better approach in many situations.</p>]]></description> + + </rule> <rule key="EI_EXPOSE_REP2"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name> <![CDATA[Malicious code vulnerability - May expose internal representation by incorporating reference to mutable object]]></name> <configKey><![CDATA[EI_EXPOSE_REP2]]></configKey> - - <description><![CDATA[<p> This code stores a reference to an externally mutable object into the - internal representation of the object. - If instances - are accessed by untrusted code, and unchecked changes to - the mutable object would compromise security or other - important properties, you will need to do something different. - Storing a copy of the object is better approach in many situations.</p>]]></description> + + </rule> <rule key="EI_EXPOSE_STATIC_REP2"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name> <![CDATA[Malicious code vulnerability - May expose internal static state by storing a mutable object into a static field]]></name> <configKey><![CDATA[EI_EXPOSE_STATIC_REP2]]></configKey> - - <description><![CDATA[<p> This code stores a reference to an externally mutable object into a static - field. - If unchecked changes to - the mutable object would compromise security or other - important properties, you will need to do something different. - Storing a copy of the object is better approach in many situations.</p>]]></description> + + </rule> <rule key="RU_INVOKE_RUN"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Multithreaded correctness - Invokes run on a thread (did you mean to start it instead?)]]></name> <configKey><![CDATA[RU_INVOKE_RUN]]></configKey> - - <description><![CDATA[<p> This method explicitly invokes <code>run()</code> on an object. - In general, classes implement the <code>Runnable</code> interface because - they are going to have their <code>run()</code> method invoked in a new thread, - in which case <code>Thread.start()</code> is the right method to call.</p>]]></description> + + </rule> <rule key="SP_SPIN_ON_FIELD"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Multithreaded correctness - Method spins on field]]></name> <configKey><![CDATA[SP_SPIN_ON_FIELD]]></configKey> - - <description><![CDATA[<p> This method spins in a loop which reads a field. The compiler - may legally hoist the read out of the loop, turning the code into an - infinite loop. The class should be changed so it uses proper - synchronization (including wait and notify calls).</p>]]></description> + + </rule> <rule key="NS_DANGEROUS_NON_SHORT_CIRCUIT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Potentially dangerous use of non-short-circuit logic]]></name> <configKey><![CDATA[NS_DANGEROUS_NON_SHORT_CIRCUIT]]></configKey> - - <description><![CDATA[<p> This code seems to be using non-short-circuit logic (e.g., & -or |) -rather than short-circuit logic (&& or ||). In addition, -it seem possible that, depending on the value of the left hand side, you might not -want to evaluate the right hand side (because it would have side effects, could cause an exception -or could be expensive.</p> -<p> -Non-short-circuit logic causes both sides of the expression -to be evaluated even when the result can be inferred from -knowing the left-hand side. This can be less efficient and -can result in errors if the left-hand side guards cases -when evaluating the right-hand side can generate an error. -</p> - -<p>See <a href="http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.22.2">the Java -Language Specification</a> for details - -</p>]]></description> + + </rule> <rule key="NS_NON_SHORT_CIRCUIT"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Dodgy - Questionable use of non-short-circuit logic]]></name> <configKey><![CDATA[NS_NON_SHORT_CIRCUIT]]></configKey> - - <description><![CDATA[<p> This code seems to be using non-short-circuit logic (e.g., & -or |) -rather than short-circuit logic (&& or ||). -Non-short-circuit logic causes both sides of the expression -to be evaluated even when the result can be inferred from -knowing the left-hand side. This can be less efficient and -can result in errors if the left-hand side guards cases -when evaluating the right-hand side can generate an error. -<p>See <a href="http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.22.2">the Java -Language Specification</a> for details -</p>]]></description> </rule> <rule key="TLW_TWO_LOCK_WAIT"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Multithreaded correctness - Wait with two locks held]]></name> <configKey><![CDATA[TLW_TWO_LOCK_WAIT]]></configKey> - - <description><![CDATA[<p> Waiting on a monitor while two locks are held may cause - deadlock. - - Performing a wait only releases the lock on the object - being waited on, not any other locks. - -This not necessarily a bug, but is worth examining - closely.</p>]]></description> + + </rule> <rule key="UW_UNCOND_WAIT"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Multithreaded correctness - Unconditional wait]]></name> <configKey><![CDATA[UW_UNCOND_WAIT]]></configKey> - - <description><![CDATA[<p> This method contains a call to <code>java.lang.Object.wait()</code> which - is not guarded by conditional control flow. The code should - verify that condition it intends to wait for is not already satisfied - before calling wait; any previous notifications will be ignored. - </p>]]></description> + + </rule> <rule key="UR_UNINIT_READ"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Uninitialized read of field in constructor]]></name> <configKey><![CDATA[UR_UNINIT_READ]]></configKey> - - <description><![CDATA[<p> This constructor reads a field which has not yet been assigned a value. - This is often caused when the programmer mistakenly uses the field instead - of one of the constructor's parameters.</p>]]></description> + + </rule> <rule key="UG_SYNC_SET_UNSYNC_GET"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Multithreaded correctness - Unsynchronized get method, synchronized set method]]></name> <configKey><![CDATA[UG_SYNC_SET_UNSYNC_GET]]></configKey> - - <description><![CDATA[<p> This class contains similarly-named get and set - methods where the set method is synchronized and the get method is not. - This may result in incorrect behavior at runtime, as callers of the get - method will not necessarily see a consistent state for the object. - The get method should be made synchronized.</p>]]></description> + + </rule> <rule key="IC_INIT_CIRCULARITY"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Initialization circularity]]></name> <configKey><![CDATA[IC_INIT_CIRCULARITY]]></configKey> - - <description><![CDATA[<p> A circularity was detected in the static initializers of the two - classes referenced by the bug instance. Many kinds of unexpected - behavior may arise from such circularity.</p>]]></description> + + </rule> <rule key="IC_SUPERCLASS_USES_SUBCLASS_DURING_INITIALIZATION"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Superclass uses subclass during initialization]]></name> <configKey><![CDATA[IC_SUPERCLASS_USES_SUBCLASS_DURING_INITIALIZATION]]></configKey> - - <description><![CDATA[<p> During the initialization of a class, the class makes an active use of a subclass. -That subclass will not yet be initialized at the time of this use. -For example, in the following code, <code>foo</code> will be null.</p> - -<pre> -public class CircularClassInitialization { - static class InnerClassSingleton extends CircularClassInitialization { - static InnerClassSingleton singleton = new InnerClassSingleton(); - } - - static CircularClassInitialization foo = InnerClassSingleton.singleton; -} -</pre>]]></description> + + </rule> <rule key="IT_NO_SUCH_ELEMENT"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Bad practice - Iterator next() method can't throw NoSuchElementException]]></name> <configKey><![CDATA[IT_NO_SUCH_ELEMENT]]></configKey> - - <description><![CDATA[<p> This class implements the <code>java.util.Iterator</code> interface. - However, its <code>next()</code> method is not capable of throwing - <code>java.util.NoSuchElementException</code>. The <code>next()</code> - method should be changed so it throws <code>NoSuchElementException</code> - if is called when there are no more elements to return.</p>]]></description> + + </rule> <rule key="DL_SYNCHRONIZATION_ON_SHARED_CONSTANT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Synchronization on interned String could lead to deadlock]]></name> <configKey><![CDATA[DL_SYNCHRONIZATION_ON_SHARED_CONSTANT]]></configKey> - - <description><![CDATA[<p> The code synchronizes on interned String. -<pre> -private static String LOCK = "LOCK"; -... - synchronized(LOCK) { ...} -... -</pre> -</p> -<p>Constant Strings are interned and shared across all other classes loaded by the JVM. Thus, this could -is locking on something that other code might also be locking. This could result in very strange and hard to diagnose -blocking and deadlock behavior. See <a href="http://www.javalobby.org/java/forums/t96352.html">http://www.javalobby.org/java/forums/t96352.html</a> and <a href="http://jira.codehaus.org/browse/JETTY-352">http://jira.codehaus.org/browse/JETTY-352</a>. -</p>]]></description> + + </rule> <rule key="DL_SYNCHRONIZATION_ON_BOOLEAN"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Synchronization on Boolean could lead to deadlock]]></name> <configKey><![CDATA[DL_SYNCHRONIZATION_ON_BOOLEAN]]></configKey> - - <description><![CDATA[<p> The code synchronizes on a boxed primitive constant, such as an Boolean. -<pre> -private static Boolean inited = Boolean.FALSE; -... - synchronized(inited) { - if (!inited) { - init(); - inited = Boolean.TRUE; - } - } -... -</pre> -</p> -<p>Since there normally exist only two Boolean objects, this code could be synchronizing on the same object as other, unrelated code, leading to unresponsiveness -and possible deadlock</p>]]></description> + + </rule> <rule key="DL_SYNCHRONIZATION_ON_UNSHARED_BOXED_PRIMITIVE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Synchronization on boxed primitive values]]></name> <configKey><![CDATA[DL_SYNCHRONIZATION_ON_UNSHARED_BOXED_PRIMITIVE]]></configKey> - - <description><![CDATA[<p> The code synchronizes on an apparently unshared boxed primitive, -such as an Integer. -<pre> -private static final Integer fileLock = new Integer(1); -... - synchronized(fileLock) { - .. do something .. - } -... -</pre> -</p> -<p>It would be much better, in this code, to redeclare fileLock as -<pre> -private static final Object fileLock = new Object(); -</pre> -The existing code might be OK, but it is confusing and a -future refactoring, such as the "Remove Boxing" refactoring in IntelliJ, -might replace this with the use of an interned Integer object shared -throughout the JVM, leading to very confusing behavior and potential deadlock. -</p>]]></description> + + </rule> <rule key="DL_SYNCHRONIZATION_ON_BOXED_PRIMITIVE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Synchronization on boxed primitive could lead to deadlock]]></name> <configKey><![CDATA[DL_SYNCHRONIZATION_ON_BOXED_PRIMITIVE]]></configKey> - - <description><![CDATA[<p> The code synchronizes on a boxed primitive constant, such as an Integer. -<pre> -private static Integer count = 0; -... - synchronized(count) { - count++; - } -... -</pre> -</p> -<p>Since Integer objects can be cached and shared, -this code could be synchronizing on the same object as other, unrelated code, leading to unresponsiveness -and possible deadlock</p>]]></description> + + </rule> <rule key="ESync_EMPTY_SYNC"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Multithreaded correctness - Empty synchronized block]]></name> <configKey><![CDATA[ESync_EMPTY_SYNC]]></configKey> - - <description><![CDATA[<p> The code contains an empty synchronized block:</p> -<pre> -synchronized() {} -</pre> -<p>Empty synchronized blocks are far more subtle and hard to use correctly -than most people recognize, and empty synchronized blocks -are almost never a better solution -than less contrived solutions. -</p>]]></description> + + </rule> <rule key="IS_INCONSISTENT_SYNC"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Multithreaded correctness - Inconsistent synchronization]]></name> <configKey><![CDATA[IS_INCONSISTENT_SYNC]]></configKey> - - <description><![CDATA[<p> The fields of this class appear to be accessed inconsistently with respect - to synchronization. This bug report indicates that the bug pattern detector - judged that - </p> - <ol> - <li> The class contains a mix of locked and unlocked accesses,</li> - <li> At least one locked access was performed by one of the class's own methods, and</li> - <li> The number of unsynchronized field accesses (reads and writes) was no more than - one third of all accesses, with writes being weighed twice as high as reads</li> - </ol> - - <p> A typical bug matching this bug pattern is forgetting to synchronize - one of the methods in a class that is intended to be thread-safe.</p> - - <p> Note that there are various sources of inaccuracy in this detector; - for example, the detector cannot statically detect all situations in which - a lock is held. Also, even when the detector is accurate in - distinguishing locked vs. unlocked accesses, the code in question may still - be correct.</p>]]></description> + + </rule> <rule key="ML_SYNC_ON_FIELD_TO_GUARD_CHANGING_THAT_FIELD"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Multithreaded correctness - Synchronization on field in futile attempt to guard that field]]></name> <configKey><![CDATA[ML_SYNC_ON_FIELD_TO_GUARD_CHANGING_THAT_FIELD]]></configKey> - - <description><![CDATA[<p> This method synchronizes on a field in what appears to be an attempt -to guard against simultaneous updates to that field. But guarding a field -gets a lock on the referenced object, not on the field. This may not -provide the mutual exclusion you need, and other threads might -be obtaining locks on the referenced objects (for other purposes). An example -of this pattern would be: - -<p><pre> -private Long myNtfSeqNbrCounter = new Long(0); -private Long getNotificationSequenceNumber() { - Long result = null; - synchronized(myNtfSeqNbrCounter) { - result = new Long(myNtfSeqNbrCounter.longValue() + 1); - myNtfSeqNbrCounter = new Long(result.longValue()); - } - return result; - } -</pre> - - -</p>]]></description> + + </rule> <rule key="ML_SYNC_ON_UPDATED_FIELD"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Multithreaded correctness - Method synchronizes on an updated field]]></name> <configKey><![CDATA[ML_SYNC_ON_UPDATED_FIELD]]></configKey> - - <description><![CDATA[<p> This method synchronizes on an object - referenced from a mutable field. - This is unlikely to have useful semantics, since different -threads may be synchronizing on different objects.</p>]]></description> + + </rule> <rule key="MS_OOI_PKGPROTECT"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name> <![CDATA[Malicious code vulnerability - Field should be moved out of an interface and made package protected]]></name> <configKey><![CDATA[MS_OOI_PKGPROTECT]]></configKey> - - <description><![CDATA[<p> - A final static field that is -defined in an interface references a mutable - object such as an array or hashtable. - This mutable object could - be changed by malicious code or - by accident from another package. - To solve this, the field needs to be moved to a class - and made package protected - to avoid - this vulnerability.</p>]]></description> + + </rule> <rule key="MS_FINAL_PKGPROTECT"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Malicious code vulnerability - Field should be both final and package protected]]></name> <configKey><![CDATA[MS_FINAL_PKGPROTECT]]></configKey> - - <description><![CDATA[<p> - A mutable static field could be changed by malicious code or - by accident from another package. - The field could be made package protected and/or made final - to avoid - this vulnerability.</p>]]></description> + + </rule> <rule key="MS_SHOULD_BE_FINAL"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Malicious code vulnerability - Field isn't final but should be]]></name> <configKey><![CDATA[MS_SHOULD_BE_FINAL]]></configKey> - - <description><![CDATA[<p> - A mutable static field could be changed by malicious code or - by accident from another package. - The field could be made final to avoid - this vulnerability.</p>]]></description> + + </rule> <rule key="MS_PKGPROTECT"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Malicious code vulnerability - Field should be package protected]]></name> <configKey><![CDATA[MS_PKGPROTECT]]></configKey> - - <description><![CDATA[<p> A mutable static field could be changed by malicious code or - by accident. - The field could be made package protected to avoid - this vulnerability.</p>]]></description> + + </rule> <rule key="MS_MUTABLE_HASHTABLE"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Malicious code vulnerability - Field is a mutable Hashtable]]></name> <configKey><![CDATA[MS_MUTABLE_HASHTABLE]]></configKey> - - <description><![CDATA[<p>A final static field references a Hashtable - and can be accessed by malicious code or - by accident from another package. - This code can freely modify the contents of the Hashtable.</p>]]></description> + + </rule> <rule key="MS_MUTABLE_ARRAY"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Malicious code vulnerability - Field is a mutable array]]></name> <configKey><![CDATA[MS_MUTABLE_ARRAY]]></configKey> - - <description><![CDATA[<p> A final static field references an array - and can be accessed by malicious code or - by accident from another package. - This code can freely modify the contents of the array.</p>]]></description> + + </rule> <rule key="MS_CANNOT_BE_FINAL"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Malicious code vulnerability - Field isn't final and can't be protected from malicious code]]></name> <configKey><![CDATA[MS_CANNOT_BE_FINAL]]></configKey> - - <description><![CDATA[<p> - A mutable static field could be changed by malicious code or - by accident from another package. - Unfortunately, the way the field is used doesn't allow - any easy fix to this problem.</p>]]></description> + + </rule> <rule key="IA_AMBIGUOUS_INVOCATION_OF_INHERITED_OR_OUTER_METHOD"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Dodgy - Ambiguous invocation of either an inherited or outer method]]></name> <configKey><![CDATA[IA_AMBIGUOUS_INVOCATION_OF_INHERITED_OR_OUTER_METHOD]]></configKey> - - <description><![CDATA[<p> An inner class is invoking a method that could be resolved to either a inherited method or a method defined in an outer class. By the Java semantics, -it will be resolved to invoke the inherited method, but this may not be want -you intend. If you really intend to invoke the inherited method, -invoke it by invoking the method on super (e.g., invoke super.foo(17)), and -thus it will be clear to other readers of your code and to FindBugs -that you want to invoke the inherited method, not the method in the outer class. -</p>]]></description> + + </rule> <rule key="NM_SAME_SIMPLE_NAME_AS_SUPERCLASS"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Class names shouldn't shadow simple name of superclass]]></name> <configKey><![CDATA[NM_SAME_SIMPLE_NAME_AS_SUPERCLASS]]></configKey> - - <description><![CDATA[<p> This class has a simple name that is identical to that of its superclass, except -that its superclass is in a different package (e.g., <code>alpha.Foo</code> extends <code>beta.Foo</code>). -This can be exceptionally confusing, create lots of situations in which you have to look at import statements -to resolve references and creates many -opportunities to accidently define methods that do not override methods in their superclasses. -</p>]]></description> + + </rule> <rule key="NM_SAME_SIMPLE_NAME_AS_INTERFACE"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Class names shouldn't shadow simple name of implemented interface]]></name> <configKey><![CDATA[NM_SAME_SIMPLE_NAME_AS_INTERFACE]]></configKey> - - <description><![CDATA[<p> This class/interface has a simple name that is identical to that of an implemented/extended interface, except -that the interface is in a different package (e.g., <code>alpha.Foo</code> extends <code>beta.Foo</code>). -This can be exceptionally confusing, create lots of situations in which you have to look at import statements -to resolve references and creates many -opportunities to accidently define methods that do not override methods in their superclasses. -</p>]]></description> + + </rule> <rule key="NM_VERY_CONFUSING"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Very confusing method names]]></name> <configKey><![CDATA[NM_VERY_CONFUSING]]></configKey> - - <description><![CDATA[<p> The referenced methods have names that differ only by capitalization. -This is very confusing because if the capitalization were -identical then one of the methods would override the other. -</p>]]></description> + + </rule> <rule key="NM_VERY_CONFUSING_INTENTIONAL"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Very confusing method names (but perhaps intentional)]]></name> <configKey><![CDATA[NM_VERY_CONFUSING_INTENTIONAL]]></configKey> - - <description><![CDATA[<p> The referenced methods have names that differ only by capitalization. -This is very confusing because if the capitalization were -identical then one of the methods would override the other. From the existence of other methods, it -seems that the existence of both of these methods is intentional, but is sure is confusing. -You should try hard to eliminate one of them, unless you are forced to have both due to frozen APIs. -</p>]]></description> + + </rule> <rule key="NM_WRONG_PACKAGE"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name> <![CDATA[Correctness - Method doesn't override method in superclass due to wrong package for parameter]]></name> <configKey><![CDATA[NM_WRONG_PACKAGE]]></configKey> - - <description><![CDATA[<p> The method in the subclass doesn't override a similar method in a superclass because the type of a parameter doesn't exactly match -the type of the corresponding parameter in the superclass. For example, if you have:</p> - -<blockquote> -<pre> -import alpha.Foo; -public class A { - public int f(Foo x) { return 17; } -} ----- -import beta.Foo; -public class B extends A { - public int f(Foo x) { return 42; } -} -</pre> -</blockquote> - -<p>The <code>f(Foo)</code> method defined in class <code>B</code> doesn't -override the -<code>f(Foo)</code> method defined in class <code>A</code>, because the argument -types are <code>Foo</code>'s from different packages. -</p>]]></description> + + </rule> <rule key="NM_WRONG_PACKAGE_INTENTIONAL"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name> <![CDATA[Bad practice - Method doesn't override method in superclass due to wrong package for parameter]]></name> <configKey><![CDATA[NM_WRONG_PACKAGE_INTENTIONAL]]></configKey> - - <description><![CDATA[<p> The method in the subclass doesn't override a similar method in a superclass because the type of a parameter doesn't exactly match -the type of the corresponding parameter in the superclass. For example, if you have:</p> - -<blockquote> -<pre> -import alpha.Foo; -public class A { - public int f(Foo x) { return 17; } -} ----- -import beta.Foo; -public class B extends A { - public int f(Foo x) { return 42; } - public int f(alpha.Foo x) { return 27; } -} -</pre> -</blockquote> - -<p>The <code>f(Foo)</code> method defined in class <code>B</code> doesn't -override the -<code>f(Foo)</code> method defined in class <code>A</code>, because the argument -types are <code>Foo</code>'s from different packages. -</p> - -<p>In this case, the subclass does define a method with a signature identical to the method in the superclass, -so this is presumably understood. However, such methods are exceptionally confusing. You should strongly consider -removing or deprecating the method with the similar but not identical signature. -</p>]]></description> + + </rule> <rule key="NM_CONFUSING"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Confusing method names]]></name> <configKey><![CDATA[NM_CONFUSING]]></configKey> - - <description><![CDATA[<p> The referenced methods have names that differ only by capitalization.</p>]]></description> + + </rule> <rule key="NM_METHOD_CONSTRUCTOR_CONFUSION"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Apparent method/constructor confusion]]></name> <configKey><![CDATA[NM_METHOD_CONSTRUCTOR_CONFUSION]]></configKey> - - <description><![CDATA[<p> This regular method has the same name as the class it is defined in. It is likely that this was intended to be a constructor. - If it was intended to be a constructor, remove the declaration of a void return value. - If you had accidently defined this method, realized the mistake, defined a proper constructor - but can't get rid of this method due to backwards compatibility, deprecate the method. -</p>]]></description> + + </rule> <rule key="NM_CLASS_NOT_EXCEPTION"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Class is not derived from an Exception, even though it is named as such]]></name> <configKey><![CDATA[NM_CLASS_NOT_EXCEPTION]]></configKey> - - <description><![CDATA[<p> This class is not derived from another exception, but ends with 'Exception'. This will -be confusing to users of this class.</p>]]></description> + + </rule> <rule key="RR_NOT_CHECKED"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Method ignores results of InputStream.read()]]></name> <configKey><![CDATA[RR_NOT_CHECKED]]></configKey> - - <description><![CDATA[<p> This method ignores the return value of one of the variants of - <code>java.io.InputStream.read()</code> which can return multiple bytes. - If the return value is not checked, the caller will not be able to correctly - handle the case where fewer bytes were read than the caller requested. - This is a particularly insidious kind of bug, because in many programs, - reads from input streams usually do read the full amount of data requested, - causing the program to fail only sporadically.</p>]]></description> + + </rule> <rule key="SR_NOT_CHECKED"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Method ignores results of InputStream.skip()]]></name> <configKey><![CDATA[SR_NOT_CHECKED]]></configKey> - - <description><![CDATA[<p> This method ignores the return value of - <code>java.io.InputStream.skip()</code> which can skip multiple bytes. - If the return value is not checked, the caller will not be able to correctly - handle the case where fewer bytes were skipped than the caller requested. - This is a particularly insidious kind of bug, because in many programs, - skips from input streams usually do skip the full amount of data requested, - causing the program to fail only sporadically. With Buffered streams, however, - skip() will only skip data in the buffer, and will routinely fail to skip the - requested number of bytes.</p>]]></description> + + </rule> <rule key="SE_READ_RESOLVE_IS_STATIC"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - The readResolve method must not be declared as a static method. ]]></name> <configKey><![CDATA[SE_READ_RESOLVE_IS_STATIC]]></configKey> - - <description><![CDATA[<p> In order for the readResolve method to be recognized by the serialization -mechanism, it must not be declared as a static method. -</p>]]></description> + + </rule> <rule key="SE_PRIVATE_READ_RESOLVE_NOT_INHERITED"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Dodgy - private readResolve method not inherited by subclasses]]></name> <configKey><![CDATA[SE_PRIVATE_READ_RESOLVE_NOT_INHERITED]]></configKey> - - <description><![CDATA[<p> This class defines a private readResolve method. Since it is private, it won't be inherited by subclasses. -This might be intentional and OK, but should be reviewed to ensure it is what is intended. -</p>]]></description> + + </rule> <rule key="SE_READ_RESOLVE_MUST_RETURN_OBJECT"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - The readResolve method must be declared with a return type of Object. ]]></name> <configKey><![CDATA[SE_READ_RESOLVE_MUST_RETURN_OBJECT]]></configKey> - - <description><![CDATA[<p> In order for the readResolve method to be recognized by the serialization -mechanism, it must be declared to have a return type of Object. -</p>]]></description> + + </rule> <rule key="SE_TRANSIENT_FIELD_OF_NONSERIALIZABLE_CLASS"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Dodgy - Transient field of class that isn't Serializable. ]]></name> <configKey><![CDATA[SE_TRANSIENT_FIELD_OF_NONSERIALIZABLE_CLASS]]></configKey> - - <description><![CDATA[<p> The field is marked as transient, but the class isn't Serializable, so marking it as transient -has absolutely no effect. -This may be leftover marking from a previous version of the code in which the class was transient, or -it may indicate a misunderstanding of how serialization works. -</p>]]></description> + + </rule> <rule key="SE_TRANSIENT_FIELD_NOT_RESTORED"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Transient field that isn't set by deserialization. ]]></name> <configKey><![CDATA[SE_TRANSIENT_FIELD_NOT_RESTORED]]></configKey> - - <description><![CDATA[<p> This class contains a field that is updated at multiple places in the class, thus it seems to be part of the state of the class. However, since the field is marked as transient and not set in readObject or readResolve, it will contain the default value in any -deserialized instance of the class. -</p>]]></description> + + </rule> <rule key="SE_METHOD_MUST_BE_PRIVATE"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Method must be private in order for serialization to work]]></name> <configKey><![CDATA[SE_METHOD_MUST_BE_PRIVATE]]></configKey> - - <description><![CDATA[<p> This class implements the <code>Serializable</code> interface, and defines a method - for custom serialization/deserialization. But since that method isn't declared private, - it will be silently ignored by the serialization/deserialization API.</p>]]></description> + + </rule> <rule key="SE_NO_SUITABLE_CONSTRUCTOR_FOR_EXTERNALIZATION"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Class is Externalizable but doesn't define a void constructor]]></name> <configKey><![CDATA[SE_NO_SUITABLE_CONSTRUCTOR_FOR_EXTERNALIZATION]]></configKey> - - <description><![CDATA[<p> This class implements the <code>Externalizable</code> interface, but does - not define a void constructor. When Externalizable objects are deserialized, - they first need to be constructed by invoking the void - constructor. Since this class does not have one, - serialization and deserialization will fail at runtime.</p>]]></description> + + </rule> <rule key="SE_NO_SUITABLE_CONSTRUCTOR"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Class is Serializable but its superclass doesn't define a void constructor]]></name> <configKey><![CDATA[SE_NO_SUITABLE_CONSTRUCTOR]]></configKey> - - <description><![CDATA[<p> This class implements the <code>Serializable</code> interface - and its superclass does not. When such an object is deserialized, - the fields of the superclass need to be initialized by - invoking the void constructor of the superclass. - Since the superclass does not have one, - serialization and deserialization will fail at runtime.</p>]]></description> + + </rule> <rule key="SE_NO_SERIALVERSIONID"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Class is Serializable, but doesn't define serialVersionUID]]></name> <configKey><![CDATA[SE_NO_SERIALVERSIONID]]></configKey> - - <description><![CDATA[<p> This class implements the <code>Serializable</code> interface, but does - not define a <code>serialVersionUID</code> field. - A change as simple as adding a reference to a .class object - will add synthetic fields to the class, - which will unfortunately change the implicit - serialVersionUID (e.g., adding a reference to <code>String.class</code> - will generate a static field <code>class$java$lang$String</code>). - Also, different source code to bytecode compilers may use different - naming conventions for synthetic variables generated for - references to class objects or inner classes. - To ensure interoperability of Serializable across versions, - consider adding an explicit serialVersionUID.</p>]]></description> + + </rule> <rule key="SE_COMPARATOR_SHOULD_BE_SERIALIZABLE"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Comparator doesn't implement Serializable]]></name> <configKey><![CDATA[SE_COMPARATOR_SHOULD_BE_SERIALIZABLE]]></configKey> - - <description><![CDATA[<p> This class implements the <code>Comparator</code> interface. You -should consider whether or not it should also implement the <code>Serializable</code> -interface. If a comparator is used to construct an ordered collection -such as a <code>TreeMap</code>, then the <code>TreeMap</code> -will be serializable only if the comparator is also serializable. -As most comparators have little or no state, making them serializable -is generally easy and good defensive programming. -</p>]]></description> + + </rule> <rule key="WS_WRITEOBJECT_SYNC"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name> <![CDATA[Multithreaded correctness - Class's writeObject() method is synchronized but nothing else is]]></name> <configKey><![CDATA[WS_WRITEOBJECT_SYNC]]></configKey> - - <description><![CDATA[<p> This class has a <code>writeObject()</code> method which is synchronized; - however, no other method of the class is synchronized.</p>]]></description> + + </rule> <rule key="RS_READOBJECT_SYNC"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Class's readObject() method is synchronized]]></name> <configKey><![CDATA[RS_READOBJECT_SYNC]]></configKey> - - <description><![CDATA[<p> This serializable class defines a <code>readObject()</code> which is - synchronized. By definition, an object created by deserialization - is only reachable by one thread, and thus there is no need for - <code>readObject()</code> to be synchronized. If the <code>readObject()</code> - method itself is causing the object to become visible to another thread, - that is an example of very dubious coding style.</p>]]></description> + + </rule> <rule key="SE_NONSTATIC_SERIALVERSIONID"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - serialVersionUID isn't static]]></name> <configKey><![CDATA[SE_NONSTATIC_SERIALVERSIONID]]></configKey> - - <description><![CDATA[<p> This class defines a <code>serialVersionUID</code> field that is not static. - The field should be made static - if it is intended to specify - the version UID for purposes of serialization.</p>]]></description> + + </rule> <rule key="SE_NONFINAL_SERIALVERSIONID"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - serialVersionUID isn't final]]></name> <configKey><![CDATA[SE_NONFINAL_SERIALVERSIONID]]></configKey> - - <description><![CDATA[<p> This class defines a <code>serialVersionUID</code> field that is not final. - The field should be made final - if it is intended to specify - the version UID for purposes of serialization.</p>]]></description> + + </rule> <rule key="SE_NONLONG_SERIALVERSIONID"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - serialVersionUID isn't long]]></name> <configKey><![CDATA[SE_NONLONG_SERIALVERSIONID]]></configKey> - - <description><![CDATA[<p> This class defines a <code>serialVersionUID</code> field that is not long. - The field should be made long - if it is intended to specify - the version UID for purposes of serialization.</p>]]></description> + + </rule> <rule key="SE_BAD_FIELD_INNER_CLASS"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Bad practice - Non-serializable class has a serializable inner class]]></name> <configKey><![CDATA[SE_BAD_FIELD_INNER_CLASS]]></configKey> - - <description><![CDATA[<p> This Serializable class is an inner class of a non-serializable class. -Thus, attempts to serialize it will also attempt to associate instance of the outer -class with which it is associated, leading to a runtime error. -</p> -<p>If possible, making the inner class a static inner class should solve the -problem. Making the outer class serializable might also work, but that would -mean serializing an instance of the inner class would always also serialize the instance -of the outer class, which it often not what you really want.]]></description> + + </rule> <rule key="SE_INNER_CLASS"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Serializable inner class]]></name> <configKey><![CDATA[SE_INNER_CLASS]]></configKey> - - <description><![CDATA[<p> This Serializable class is an inner class. Any attempt to serialize -it will also serialize the associated outer instance. The outer instance is serializable, -so this won't fail, but it might serialize a lot more data than intended. -If possible, making the inner class a static inner class (also known as a nested class) should solve the -problem.]]></description> + + </rule> <rule key="SE_BAD_FIELD_STORE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Non-serializable value stored into instance field of a serializable class]]></name> <configKey><![CDATA[SE_BAD_FIELD_STORE]]></configKey> - - <description><![CDATA[<p> A non-serializable value is stored into a non-transient field -of a serializable class.</p>]]></description> + + </rule> <rule key="SC_START_IN_CTOR"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Constructor invokes Thread.start()]]></name> <configKey><![CDATA[SC_START_IN_CTOR]]></configKey> - - <description><![CDATA[<p> The constructor starts a thread. This is likely to be wrong if - the class is ever extended/subclassed, since the thread will be started - before the subclass constructor is started.</p>]]></description> + + </rule> <rule key="SS_SHOULD_BE_STATIC"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Performance - Unread field: should this field be static?]]></name> <configKey><![CDATA[SS_SHOULD_BE_STATIC]]></configKey> - - <description><![CDATA[<p> This class contains an instance final field that - is initialized to a compile-time static value. - Consider making the field static.</p>]]></description> + + </rule> <rule key="UUF_UNUSED_FIELD"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Performance - Unused field]]></name> <configKey><![CDATA[UUF_UNUSED_FIELD]]></configKey> - - <description><![CDATA[<p> This field is never used. Consider removing it from the class.</p>]]></description> + + </rule> <rule key="URF_UNREAD_FIELD"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Performance - Unread field]]></name> <configKey><![CDATA[URF_UNREAD_FIELD]]></configKey> - - <description><![CDATA[<p> This field is never read. Consider removing it from the class.</p>]]></description> + + </rule> <rule key="QF_QUESTIONABLE_FOR_LOOP"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Complicated, subtle or wrong increment in for-loop ]]></name> <configKey><![CDATA[QF_QUESTIONABLE_FOR_LOOP]]></configKey> - - <description><![CDATA[<p>Are you sure this for loop is incrementing the correct variable? - It appears that another variable is being initialized and checked - by the for loop. -</p>]]></description> + + </rule> <rule key="UWF_NULL_FIELD"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Field only ever set to null]]></name> <configKey><![CDATA[UWF_NULL_FIELD]]></configKey> - - <description><![CDATA[<p> All writes to this field are of the constant value null, and thus -all reads of the field will return null. -Check for errors, or remove it if it is useless.</p>]]></description> + + </rule> <rule key="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Write to static field from instance method]]></name> <configKey><![CDATA[ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD]]></configKey> - - <description><![CDATA[<p> This instance method writes to a static field. This is tricky to get -correct if multiple instances are being manipulated, -and generally bad practice. -</p>]]></description> + + </rule> <rule key="NP_LOAD_OF_KNOWN_NULL_VALUE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Load of known null value]]></name> <configKey><![CDATA[NP_LOAD_OF_KNOWN_NULL_VALUE]]></configKey> - - <description><![CDATA[<p> The variable referenced at this point is known to be null due to an earlier - check against null. Although this is valid, it might be a mistake (perhaps you -intended to refer to a different variable, or perhaps the earlier check to see if the -variable is null should have been a check to see if it was nonnull). -</p>]]></description> + + </rule> <rule key="NP_DEREFERENCE_OF_READLINE_VALUE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Dereference of the result of readLine() without nullcheck]]></name> <configKey><![CDATA[NP_DEREFERENCE_OF_READLINE_VALUE]]></configKey> - - <description><![CDATA[<p> The result of invoking readLine() is dereferenced without checking to see if the result is null. If there are no more lines of text -to read, readLine() will return null and dereferencing that will generate a null pointer exception. -</p>]]></description> + + </rule> <rule key="NP_IMMEDIATE_DEREFERENCE_OF_READLINE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Immediate dereference of the result of readLine()]]></name> <configKey><![CDATA[NP_IMMEDIATE_DEREFERENCE_OF_READLINE]]></configKey> - - <description><![CDATA[<p> The result of invoking readLine() is immediately dereferenced. If there are no more lines of text -to read, readLine() will return null and dereferencing that will generate a null pointer exception. -</p>]]></description> + + </rule> <rule key="SIC_INNER_SHOULD_BE_STATIC"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Performance - Should be a static inner class]]></name> <configKey><![CDATA[SIC_INNER_SHOULD_BE_STATIC]]></configKey> - - <description><![CDATA[<p> This class is an inner class, but does not use its embedded reference - to the object which created it. This reference makes the instances - of the class larger, and may keep the reference to the creator object - alive longer than necessary. If possible, the class should be - made static. -</p>]]></description> + + </rule> <rule key="SIC_INNER_SHOULD_BE_STATIC_ANON"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Performance - Could be refactored into a named static inner class]]></name> <configKey><![CDATA[SIC_INNER_SHOULD_BE_STATIC_ANON]]></configKey> - - <description><![CDATA[<p> This class is an inner class, but does not use its embedded reference - to the object which created it. This reference makes the instances - of the class larger, and may keep the reference to the creator object - alive longer than necessary. If possible, the class should be - made into a <em>static</em> inner class. Since anonymous inner -classes cannot be marked as static, doing this will require refactoring -the inner class so that it is a named inner class.</p>]]></description> + + </rule> <rule key="SIC_INNER_SHOULD_BE_STATIC_NEEDS_THIS"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Performance - Could be refactored into a static inner class]]></name> <configKey><![CDATA[SIC_INNER_SHOULD_BE_STATIC_NEEDS_THIS]]></configKey> - - <description><![CDATA[<p> This class is an inner class, but does not use its embedded reference - to the object which created it except during construction of the -inner object. This reference makes the instances - of the class larger, and may keep the reference to the creator object - alive longer than necessary. If possible, the class should be - made into a <em>static</em> inner class. Since the reference to the - outer object is required during construction of the inner instance, - the inner class will need to be refactored so as to - pass a reference to the outer instance to the constructor - for the inner class.</p>]]></description> + + </rule> <rule key="WA_NOT_IN_LOOP"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Wait not in loop ]]></name> <configKey><![CDATA[WA_NOT_IN_LOOP]]></configKey> - - <description><![CDATA[<p> This method contains a call to <code>java.lang.Object.wait()</code> - which is not in a loop. If the monitor is used for multiple conditions, - the condition the caller intended to wait for might not be the one - that actually occurred.</p>]]></description> + + </rule> <rule key="WA_AWAIT_NOT_IN_LOOP"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Condition.await() not in loop ]]></name> <configKey><![CDATA[WA_AWAIT_NOT_IN_LOOP]]></configKey> - - <description><![CDATA[<p> This method contains a call to <code>java.util.concurrent.await()</code> - (or variants) - which is not in a loop. If the object is used for multiple conditions, - the condition the caller intended to wait for might not be the one - that actually occurred.</p>]]></description> + + </rule> <rule key="NO_NOTIFY_NOT_NOTIFYALL"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Using notify() rather than notifyAll()]]></name> <configKey><![CDATA[NO_NOTIFY_NOT_NOTIFYALL]]></configKey> - - <description><![CDATA[<p> This method calls <code>notify()</code> rather than <code>notifyAll()</code>. - Java monitors are often used for multiple conditions. Calling <code>notify()</code> - only wakes up one thread, meaning that the thread woken up might not be the - one waiting for the condition that the caller just satisfied.</p>]]></description> + + </rule> <rule key="RV_CHECK_FOR_POSITIVE_INDEXOF"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Dodgy - Method checks to see if result of String.indexOf is positive]]></name> <configKey><![CDATA[RV_CHECK_FOR_POSITIVE_INDEXOF]]></configKey> - - <description><![CDATA[<p> The method invokes String.indexOf and checks to see if the result is positive or non-positive. - It is much more typical to check to see if the result is negative or non-negative. It is - positive only if the substring checked for occurs at some place other than at the beginning of - the String.</p>]]></description> + + </rule> <rule key="RV_DONT_JUST_NULL_CHECK_READLINE"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Dodgy - Method discards result of readLine after checking if it is nonnull]]></name> <configKey><![CDATA[RV_DONT_JUST_NULL_CHECK_READLINE]]></configKey> - - <description><![CDATA[<p> The value returned by readLine is discarded after checking to see if the return -value is non-null. In almost all situations, if the result is non-null, you will want -to use that non-null value. Calling readLine again will give you a different line.</p>]]></description> + + </rule> <rule key="RV_RETURN_VALUE_IGNORED"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Correctness - Method ignores return value]]></name> <configKey><![CDATA[RV_RETURN_VALUE_IGNORED]]></configKey> - - <description><![CDATA[<p> The return value of this method should be checked. One common -cause of this warning is to invoke a method on an immutable object, -thinking that it updates the object. For example, in the following code -fragment,</p> -<blockquote> -<pre> -String dateString = getHeaderField(name); -dateString.trim(); -</pre> -</blockquote> -<p>the programmer seems to be thinking that the trim() method will update -the String referenced by dateString. But since Strings are immutable, the trim() -function returns a new String value, which is being ignored here. The code -should be corrected to: </p> -<blockquote> -<pre> -String dateString = getHeaderField(name); -dateString = dateString.trim(); -</pre> -</blockquote>]]></description> + + </rule> <rule key="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Method ignores exceptional return value]]></name> <configKey><![CDATA[RV_RETURN_VALUE_IGNORED_BAD_PRACTICE]]></configKey> - - <description><![CDATA[<p> This method returns a value that is not checked. The return value should be checked -since it can indicate an unusual or unexpected function execution. For -example, the <code>File.delete()</code> method returns false -if the file could not be successfully deleted (rather than -throwing an Exception). -If you don't check the result, you won't notice if the method invocation -signals unexpected behavior by returning an atypical return value. -</p>]]></description> + + </rule> <rule key="RV_EXCEPTION_NOT_THROWN"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Exception created and dropped rather than thrown]]></name> <configKey><![CDATA[RV_EXCEPTION_NOT_THROWN]]></configKey> - - <description><![CDATA[<p> This code creates an exception (or error) object, but doesn't do anything with it. For example, -something like </p> -<blockquote> -<pre> -if (x < 0) - new IllegalArgumentException("x must be nonnegative"); -</pre> -</blockquote> -<p>It was probably the intent of the programmer to throw the created exception:</p> -<blockquote> -<pre> -if (x < 0) - throw new IllegalArgumentException("x must be nonnegative"); -</pre> -</blockquote>]]></description> + + </rule> <rule key="RV_RETURN_VALUE_IGNORED2"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Method ignores return value]]></name> <configKey><![CDATA[RV_RETURN_VALUE_IGNORED2]]></configKey> - - <description><![CDATA[<p> The return value of this method should be checked. One common -cause of this warning is to invoke a method on an immutable object, -thinking that it updates the object. For example, in the following code -fragment,</p> -<blockquote> -<pre> -String dateString = getHeaderField(name); -dateString.trim(); -</pre> -</blockquote> -<p>the programmer seems to be thinking that the trim() method will update -the String referenced by dateString. But since Strings are immutable, the trim() -function returns a new String value, which is being ignored here. The code -should be corrected to: </p> -<blockquote> -<pre> -String dateString = getHeaderField(name); -dateString = dateString.trim(); -</pre> -</blockquote>]]></description> + + </rule> <rule key="NP_ALWAYS_NULL"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Null pointer dereference]]></name> <configKey><![CDATA[NP_ALWAYS_NULL]]></configKey> - - <description><![CDATA[<p> A null pointer is dereferenced here. This will lead to a -<code>NullPointerException</code> when the code is executed.</p>]]></description> + + </rule> <rule key="NP_STORE_INTO_NONNULL_FIELD"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Store of null value into field annotated NonNull]]></name> <configKey><![CDATA[NP_STORE_INTO_NONNULL_FIELD]]></configKey> - - <description> - <![CDATA[<p> A value that could be null is stored into a field that has been annotated as NonNull. </p>]]></description> + + </rule> <rule key="NP_ALWAYS_NULL_EXCEPTION"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Null pointer dereference in method on exception path]]></name> <configKey><![CDATA[NP_ALWAYS_NULL_EXCEPTION]]></configKey> - - <description><![CDATA[<p> A pointer which is null on an exception path is dereferenced here. -This will lead to a <code>NullPointerException</code> when the code is executed. -Note that because FindBugs currently does not prune infeasible exception paths, -this may be a false warning.</p> -<p> Also note that FindBugs considers the default case of a switch statement to -be an exception path, since the default case is often infeasible.</p>]]></description> + </rule> <rule key="NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Parameter must be nonnull but is marked as nullable]]></name> <configKey><![CDATA[NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE]]></configKey> - - <description><![CDATA[<p> This parameter is always used in a way that requires it to be nonnull, -but the parameter is explicitly annotated as being Nullable. Either the use -of the parameter or the annotation is wrong. -</p>]]></description> + + </rule> <rule key="NP_NULL_ON_SOME_PATH"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Possible null pointer dereference]]></name> <configKey><![CDATA[NP_NULL_ON_SOME_PATH]]></configKey> - - <description><![CDATA[<p> There is a branch of statement that, <em>if executed,</em> guarantees that -a null value will be dereferenced, which -would generate a <code>NullPointerException</code> when the code is executed. -Of course, the problem might be that the branch or statement is infeasible and that -the null pointer exception can't ever be executed; deciding that is beyond the ability of FindBugs. -</p>]]></description> + + </rule> <rule key="NP_NULL_ON_SOME_PATH_MIGHT_BE_INFEASIBLE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Possible null pointer dereference on path that might be infeasible]]></name> <configKey><![CDATA[NP_NULL_ON_SOME_PATH_MIGHT_BE_INFEASIBLE]]></configKey> - - <description><![CDATA[<p> There is a branch of statement that, <em>if executed,</em> guarantees that -a null value will be dereferenced, which -would generate a <code>NullPointerException</code> when the code is executed. -Of course, the problem might be that the branch or statement is infeasible and that -the null pointer exception can't ever be executed; deciding that is beyond the ability of FindBugs. -Due to the fact that this value had been previously tested for nullness, this is a definite possibility. -</p>]]></description> + + </rule> <rule key="NP_NULL_ON_SOME_PATH_EXCEPTION"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Possible null pointer dereference in method on exception path]]></name> <configKey><![CDATA[NP_NULL_ON_SOME_PATH_EXCEPTION]]></configKey> - - <description><![CDATA[<p> A reference value which is null on some exception control path is -dereferenced here. This may lead to a <code>NullPointerException</code> -when the code is executed. -Note that because FindBugs currently does not prune infeasible exception paths, -this may be a false warning.</p> -<p> Also note that FindBugs considers the default case of a switch statement to -be an exception path, since the default case is often infeasible.</p>]]></description> + </rule> <rule key="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Possible null pointer dereference due to return value of called method]]></name> <configKey><![CDATA[NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE]]></configKey> - - <description><![CDATA[<p> The return value from a method is dereferenced without a null check, -and the return value of that method is one that should generally be checked -for null. This may lead to a <code>NullPointerException</code> when the code is executed. -</p>]]></description> + + </rule> <rule key="NP_NULL_PARAM_DEREF_NONVIRTUAL"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Non-virtual method call passes null for nonnull parameter]]></name> <configKey><![CDATA[NP_NULL_PARAM_DEREF_NONVIRTUAL]]></configKey> - - <description><![CDATA[<p> - A possibly-null value is passed to a nonnull method parameter. - Either the parameter is annotated as a parameter that should - always be nonnull, or analysis has shown that it will always be - dereferenced. - </p>]]></description> + + </rule> <rule key="NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Method call passes null for nonnull parameter]]></name> <configKey><![CDATA[NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS]]></configKey> - - <description><![CDATA[<p> - A possibly-null value is passed at a call site where all known - target methods require the parameter to be nonnull. - Either the parameter is annotated as a parameter that should - always be nonnull, or analysis has shown that it will always be - dereferenced. - </p>]]></description> + + </rule> <rule key="NP_NULL_PARAM_DEREF"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Method call passes null for nonnull parameter]]></name> <configKey><![CDATA[NP_NULL_PARAM_DEREF]]></configKey> - - <description><![CDATA[<p> - This method call passes a null value for a nonnull method parameter. - Either the parameter is annotated as a parameter that should - always be nonnull, or analysis has shown that it will always be - dereferenced. - </p>]]></description> + + </rule> <rule key="NP_NONNULL_PARAM_VIOLATION"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Method call passes null to a nonnull parameter ]]></name> <configKey><![CDATA[NP_NONNULL_PARAM_VIOLATION]]></configKey> - - <description><![CDATA[<p> - This method passes a null value as the parameter of a method which - must be nonnull. Either this parameter has been explicitly marked - as @Nonnull, or analysis has determined that this parameter is - always dereferenced. - </p>]]></description> + + </rule> <rule key="NP_NONNULL_RETURN_VIOLATION"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Method may return null, but is declared @NonNull]]></name> <configKey><![CDATA[NP_NONNULL_RETURN_VIOLATION]]></configKey> - - <description><![CDATA[<p> - This method may return a null value, but the method (or a superclass method - which it overrides) is declared to return @NonNull. - </p>]]></description> + + </rule> <rule key="NP_CLONE_COULD_RETURN_NULL"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Clone method may return null]]></name> <configKey><![CDATA[NP_CLONE_COULD_RETURN_NULL]]></configKey> - - <description><![CDATA[<p> - This clone method seems to return null in some circumstances, but clone is never - allowed to return a null value. If you are convinced this path is unreachable, throw an AssertionError - instead. - </p>]]></description> + + </rule> <rule key="NP_TOSTRING_COULD_RETURN_NULL"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - toString method may return null]]></name> <configKey><![CDATA[NP_TOSTRING_COULD_RETURN_NULL]]></configKey> - - <description><![CDATA[<p> - This toString method seems to return null in some circumstances. A liberal reading of the - spec could be interpreted as allowing this, but it is probably a bad idea and could cause - other code to break. Return the empty string or some other appropriate string rather than null. - </p>]]></description> + + </rule> <rule key="NP_GUARANTEED_DEREF"> -<priority>BLOCKER</priority> + <priority>BLOCKER</priority> <name><![CDATA[Correctness - Null value is guaranteed to be dereferenced]]></name> <configKey><![CDATA[NP_GUARANTEED_DEREF]]></configKey> - - <description><![CDATA[<p> - There is a statement or branch that if executed guarantees that - a value is null at this point, and that - value that is guaranteed to be dereferenced - (except on forward paths involving runtime exceptions). - </p>]]></description> + + </rule> <rule key="NP_GUARANTEED_DEREF_ON_EXCEPTION_PATH"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Value is null and guaranteed to be dereferenced on exception path]]></name> <configKey><![CDATA[NP_GUARANTEED_DEREF_ON_EXCEPTION_PATH]]></configKey> - - <description><![CDATA[<p> - There is a statement or branch on an exception path - that if executed guarantees that - a value is null at this point, and that - value that is guaranteed to be dereferenced - (except on forward paths involving runtime exceptions). - </p>]]></description> + + </rule> <rule key="SI_INSTANCE_BEFORE_FINALS_ASSIGNED"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Static initializer creates instance before all static final fields assigned]]></name> <configKey><![CDATA[SI_INSTANCE_BEFORE_FINALS_ASSIGNED]]></configKey> - - <description><![CDATA[<p> The class's static initializer creates an instance of the class -before all of the static final fields are assigned.</p>]]></description> + + </rule> <rule key="OS_OPEN_STREAM"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Method may fail to close stream]]></name> <configKey><![CDATA[OS_OPEN_STREAM]]></configKey> - - <description><![CDATA[<p> The method creates an IO stream object, does not assign it to any -fields, pass it to other methods that might close it, -or return it, and does not appear to close -the stream on all paths out of the method. This may result in -a file descriptor leak. It is generally a good -idea to use a <code>finally</code> block to ensure that streams are -closed.</p>]]></description> + + </rule> <rule key="OS_OPEN_STREAM_EXCEPTION_PATH"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Method may fail to close stream on exception]]></name> <configKey><![CDATA[OS_OPEN_STREAM_EXCEPTION_PATH]]></configKey> - - <description><![CDATA[<p> The method creates an IO stream object, does not assign it to any -fields, pass it to other methods, or return it, and does not appear to close -it on all possible exception paths out of the method. -This may result in a file descriptor leak. It is generally a good -idea to use a <code>finally</code> block to ensure that streams are -closed.</p>]]></description> + + </rule> <rule key="PZLA_PREFER_ZERO_LENGTH_ARRAYS"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Dodgy - Consider returning a zero length array rather than null]]></name> <configKey><![CDATA[PZLA_PREFER_ZERO_LENGTH_ARRAYS]]></configKey> - - <description><![CDATA[<p> It is often a better design to -return a length zero array rather than a null reference to indicate that there -are no results (i.e., an empty list of results). -This way, no explicit check for null is needed by clients of the method.</p> - -<p>On the other hand, using null to indicate -"there is no answer to this question" is probably appropriate. -For example, <code>File.listFiles()</code> returns an empty list -if given a directory containing no files, and returns null if the file -is not a directory.</p>]]></description> + + </rule> <rule key="UCF_USELESS_CONTROL_FLOW"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Useless control flow]]></name> <configKey><![CDATA[UCF_USELESS_CONTROL_FLOW]]></configKey> - - <description><![CDATA[<p> This method contains a useless control flow statement, where -control flow continues onto the same place regardless of whether or not -the branch is taken. For example, -this is caused by having an empty statement -block for an <code>if</code> statement:</p> -<pre> - if (argv.length == 0) { - // TODO: handle this case - } -</pre>]]></description> + + </rule> <rule key="UCF_USELESS_CONTROL_FLOW_NEXT_LINE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Useless control flow to next line]]></name> <configKey><![CDATA[UCF_USELESS_CONTROL_FLOW_NEXT_LINE]]></configKey> - - <description><![CDATA[<p> This method contains a useless control flow statement in which control -flow follows to the same or following line regardless of whether or not -the branch is taken. -Often, this is caused by inadvertently using an empty statement as the -body of an <code>if</code> statement, e.g.:</p> -<pre> - if (argv.length == 1); - System.out.println("Hello, " + argv[0]); -</pre>]]></description> + + </rule> <rule key="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Nullcheck of value previously dereferenced]]></name> <configKey><![CDATA[RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE]]></configKey> - - <description><![CDATA[<p> A value is checked here to see whether it is null, but this value can't -be null because it was previously dereferenced and if it were null a null pointer -exception would have occurred at the earlier dereference. -Essentially, this code and the previous dereference -disagree as to whether this value is allowed to be null. Either the check is redundant -or the previous dereference is erroneous.</p>]]></description> + + </rule> <rule key="RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Redundant nullcheck of value known to be null]]></name> <configKey><![CDATA[RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE]]></configKey> - - <description><![CDATA[<p> This method contains a redundant check of a known null value against -the constant null.</p>]]></description> + + </rule> <rule key="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Redundant nullcheck of value known to be non-null]]></name> <configKey><![CDATA[RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE]]></configKey> - - <description><![CDATA[<p> This method contains a redundant check of a known non-null value against -the constant null.</p>]]></description> + + </rule> <rule key="RCN_REDUNDANT_COMPARISON_TWO_NULL_VALUES"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Redundant comparison of two null values]]></name> <configKey><![CDATA[RCN_REDUNDANT_COMPARISON_TWO_NULL_VALUES]]></configKey> - - <description><![CDATA[<p> This method contains a redundant comparison of two references known to -both be definitely null.</p>]]></description> + + </rule> <rule key="RCN_REDUNDANT_COMPARISON_OF_NULL_AND_NONNULL_VALUE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Redundant comparison of non-null value to null]]></name> <configKey><![CDATA[RCN_REDUNDANT_COMPARISON_OF_NULL_AND_NONNULL_VALUE]]></configKey> - - <description><![CDATA[<p> This method contains a reference known to be non-null with another reference -known to be null.</p>]]></description> + + </rule> <rule key="UL_UNRELEASED_LOCK"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Method does not release lock on all paths]]></name> <configKey><![CDATA[UL_UNRELEASED_LOCK]]></configKey> - - <description><![CDATA[<p> This method acquires a JSR-166 (<code>java.util.concurrent</code>) lock, -but does not release it on all paths out of the method. In general, the correct idiom -for using a JSR-166 lock is: -</p> -<pre> - Lock l = ...; - l.lock(); - try { - // do something - } finally { - l.unlock(); - } -</pre>]]></description> + + </rule> <rule key="UL_UNRELEASED_LOCK_EXCEPTION_PATH"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Method does not release lock on all exception paths]]></name> <configKey><![CDATA[UL_UNRELEASED_LOCK_EXCEPTION_PATH]]></configKey> - - <description><![CDATA[<p> This method acquires a JSR-166 (<code>java.util.concurrent</code>) lock, -but does not release it on all exception paths out of the method. In general, the correct idiom -for using a JSR-166 lock is: -</p> -<pre> - Lock l = ...; - l.lock(); - try { - // do something - } finally { - l.unlock(); - } -</pre>]]></description> + + </rule> <rule key="RC_REF_COMPARISON"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Suspicious reference comparison]]></name> <configKey><![CDATA[RC_REF_COMPARISON]]></configKey> - - <description><![CDATA[<p> This method compares two reference values using the == or != operator, -where the correct way to compare instances of this type is generally -with the equals() method. Examples of classes which should generally -not be compared by reference are java.lang.Integer, java.lang.Float, etc.</p>]]></description> + + </rule> <rule key="EC_UNRELATED_TYPES_USING_POINTER_EQUALITY"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Using pointer equality to compare different types]]></name> <configKey><![CDATA[EC_UNRELATED_TYPES_USING_POINTER_EQUALITY]]></configKey> - - <description><![CDATA[<p> This method uses using pointer equality to compare two references that seem to be of -different types. The result of this comparison will always be false at runtime. -</p>]]></description> + + </rule> <rule key="EC_UNRELATED_TYPES"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Call to equals() comparing different types]]></name> <configKey><![CDATA[EC_UNRELATED_TYPES]]></configKey> - - <description><![CDATA[<p> This method calls equals(Object) on two references of different -class types with no common subclasses. -Therefore, the objects being compared -are unlikely to be members of the same class at runtime -(unless some application classes were not analyzed, or dynamic class -loading can occur at runtime). -According to the contract of equals(), -objects of different -classes should always compare as unequal; therefore, according to the -contract defined by java.lang.Object.equals(Object), -the result of this comparison will always be false at runtime. -</p>]]></description> + + </rule> <rule key="EC_UNRELATED_INTERFACES"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Call to equals() comparing different interface types]]></name> <configKey><![CDATA[EC_UNRELATED_INTERFACES]]></configKey> - - <description><![CDATA[<p> This method calls equals(Object) on two references of unrelated -interface types, where neither is a subtype of the other, -and there are no known non-abstract classes which implement both interfaces. -Therefore, the objects being compared -are unlikely to be members of the same class at runtime -(unless some application classes were not analyzed, or dynamic class -loading can occur at runtime). -According to the contract of equals(), -objects of different -classes should always compare as unequal; therefore, according to the -contract defined by java.lang.Object.equals(Object), -the result of this comparison will always be false at runtime. -</p>]]></description> + + </rule> <rule key="EC_UNRELATED_CLASS_AND_INTERFACE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Call to equals() comparing unrelated class and interface]]></name> <configKey><![CDATA[EC_UNRELATED_CLASS_AND_INTERFACE]]></configKey> - - <description><![CDATA[<p> -This method calls equals(Object) on two references, one of which is a class -and the other an interface, where neither the class nor any of its -non-abstract subclasses implement the interface. -Therefore, the objects being compared -are unlikely to be members of the same class at runtime -(unless some application classes were not analyzed, or dynamic class -loading can occur at runtime). -According to the contract of equals(), -objects of different -classes should always compare as unequal; therefore, according to the -contract defined by java.lang.Object.equals(Object), -the result of this comparison will always be false at runtime. -</p>]]></description> + + </rule> <rule key="EC_NULL_ARG"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Call to equals() with null argument]]></name> <configKey><![CDATA[EC_NULL_ARG]]></configKey> - - <description><![CDATA[<p> This method calls equals(Object), passing a null value as -the argument. According to the contract of the equals() method, -this call should always return <code>false</code>.</p>]]></description> + + </rule> <rule key="MWN_MISMATCHED_WAIT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Mismatched wait()]]></name> <configKey><![CDATA[MWN_MISMATCHED_WAIT]]></configKey> - - <description><![CDATA[<p> This method calls Object.wait() without obviously holding a lock -on the object. Calling wait() without a lock held will result in -an <code>IllegalMonitorStateException</code> being thrown.</p>]]></description> + + </rule> <rule key="MWN_MISMATCHED_NOTIFY"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Mismatched notify()]]></name> <configKey><![CDATA[MWN_MISMATCHED_NOTIFY]]></configKey> - - <description><![CDATA[<p> This method calls Object.notify() or Object.notifyAll() without obviously holding a lock -on the object. Calling notify() or notifyAll() without a lock held will result in -an <code>IllegalMonitorStateException</code> being thrown.</p>]]></description> + + </rule> <rule key="SA_LOCAL_SELF_ASSIGNMENT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Self assignment of local variable]]></name> <configKey><![CDATA[SA_LOCAL_SELF_ASSIGNMENT]]></configKey> - - <description><![CDATA[<p> This method contains a self assignment of a local variable; e.g.</p> -<pre> - public void foo() { - int x = 3; - x = x; - } -</pre> -<p> -Such assignments are useless, and may indicate a logic error or typo. -</p>]]></description> + + </rule> <rule key="SA_FIELD_SELF_ASSIGNMENT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Self assignment of field]]></name> <configKey><![CDATA[SA_FIELD_SELF_ASSIGNMENT]]></configKey> - - <description><![CDATA[<p> This method contains a self assignment of a field; e.g. -</p> -<pre> - int x; - public void foo() { - x = x; - } -</pre> -<p>Such assignments are useless, and may indicate a logic error or typo.</p>]]></description> + + </rule> <rule key="SA_FIELD_DOUBLE_ASSIGNMENT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Double assignment of field]]></name> <configKey><![CDATA[SA_FIELD_DOUBLE_ASSIGNMENT]]></configKey> - - <description><![CDATA[<p> This method contains a double assignment of a field; e.g. -</p> -<pre> - int x,y; - public void foo() { - x = x = 17; - } -</pre> -<p>Assigning to a field twice is useless, and may indicate a logic error or typo.</p>]]></description> + + </rule> <rule key="SA_LOCAL_DOUBLE_ASSIGNMENT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Double assignment of local variable ]]></name> <configKey><![CDATA[SA_LOCAL_DOUBLE_ASSIGNMENT]]></configKey> - - <description><![CDATA[<p> This method contains a double assignment of a local variable; e.g. -</p> -<pre> - public void foo() { - int x,y; - x = x = 17; - } -</pre> -<p>Assigning the same value to a variable twice is useless, and may indicate a logic error or typo.</p>]]></description> + + </rule> <rule key="SA_FIELD_SELF_COMPUTATION"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Nonsensical self computation involving a field (e.g., x & x)]]></name> <configKey><![CDATA[SA_FIELD_SELF_COMPUTATION]]></configKey> - - <description><![CDATA[<p> This method performs a nonsensical computation of a field with another -reference to the same field (e.g., x&x or x-x). Because of the nature -of the computation, this operation doesn't seem to make sense, -and may indicate a typo or -a logic error. Double check the computation. -</p>]]></description> + + </rule> <rule key="SA_LOCAL_SELF_COMPUTATION"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Nonsensical self computation involving a variable (e.g., x & x)]]></name> <configKey><![CDATA[SA_LOCAL_SELF_COMPUTATION]]></configKey> - - <description><![CDATA[<p> This method performs a nonsensical computation of a local variable with another -reference to the same variable (e.g., x&x or x-x). Because of the nature -of the computation, this operation doesn't seem to make sense, -and may indicate a typo or -a logic error. Double check the computation. -</p>]]></description> + + </rule> <rule key="SA_FIELD_SELF_COMPARISON"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Self comparison of field with itself]]></name> <configKey><![CDATA[SA_FIELD_SELF_COMPARISON]]></configKey> - - <description><![CDATA[<p> This method compares a field with itself, and may indicate a typo or -a logic error. Make sure that you are comparing the right things. -</p>]]></description> + + </rule> <rule key="SA_LOCAL_SELF_COMPARISON"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Self comparison of value with itself]]></name> <configKey><![CDATA[SA_LOCAL_SELF_COMPARISON]]></configKey> - - <description><![CDATA[<p> This method compares a local variable with itself, and may indicate a typo or -a logic error. Make sure that you are comparing the right things. -</p>]]></description> + + </rule> <rule key="DMI_LONG_BITS_TO_DOUBLE_INVOKED_ON_INT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Double.longBitsToDouble invoked on an int]]></name> <configKey><![CDATA[DMI_LONG_BITS_TO_DOUBLE_INVOKED_ON_INT]]></configKey> - - <description><![CDATA[<p> The Double.longBitsToDouble method is invoked, but a 32 bit int value is passed - as an argument. This almostly certainly is not intended and is unlikely - to give the intended result. -</p>]]></description> + + </rule> <rule key="DMI_RANDOM_USED_ONLY_ONCE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Random object created and used only once]]></name> <configKey><![CDATA[DMI_RANDOM_USED_ONLY_ONCE]]></configKey> - - <description><![CDATA[<p> This code creates a java.util.Random object, uses it to generate one random number, and then discards -the Random object. This produces mediocre quality random numbers and is inefficient. -If possible, rewrite the code so that the Random object is created once and saved, and each time a new random number -is required invoke a method on the existing Random object to obtain it. -</p> - -<p>If it is important that the generated Random numbers not be guessable, you <em>must</em> not create a new Random for each random -number; the values are too easily guessable. You should strongly consider using a java.security.SecureRandom instead -(and avoid allocating a new SecureRandom for each random number needed). -</p>]]></description> + + </rule> <rule key="RV_ABSOLUTE_VALUE_OF_RANDOM_INT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Bad attempt to compute absolute value of signed 32-bit random integer]]></name> <configKey><![CDATA[RV_ABSOLUTE_VALUE_OF_RANDOM_INT]]></configKey> - - <description><![CDATA[<p> This code generates a random signed integer and then computes -the absolute value of that random integer. If the number returned by the random number -generator is <code>Integer.MIN_VALUE</code>, then the result will be negative as well (since -<code>Math.abs(Integer.MIN_VALUE) == Integer.MIN_VALUE</code>). -</p>]]></description> + + </rule> <rule key="RV_ABSOLUTE_VALUE_OF_HASHCODE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Bad attempt to compute absolute value of signed 32-bit hashcode ]]></name> <configKey><![CDATA[RV_ABSOLUTE_VALUE_OF_HASHCODE]]></configKey> - - <description><![CDATA[<p> This code generates a hashcode and then computes -the absolute value of that hashcode. If the hashcode -is <code>Integer.MIN_VALUE</code>, then the result will be negative as well (since -<code>Math.abs(Integer.MIN_VALUE) == Integer.MIN_VALUE</code>). -</p>]]></description> + + </rule> <rule key="RV_REM_OF_RANDOM_INT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Remainder of 32-bit signed random integer]]></name> <configKey><![CDATA[RV_REM_OF_RANDOM_INT]]></configKey> - - <description><![CDATA[<p> This code generates a random signed integer and then computes -the remainder of that value modulo another value. Since the random -number can be negative, the result of the remainder operation -can also be negative. Be sure this is intended, and strongly -consider using the Random.nextInt(int) method instead. -</p>]]></description> + + </rule> <rule key="RV_REM_OF_HASHCODE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Remainder of hashCode could be negative]]></name> <configKey><![CDATA[RV_REM_OF_HASHCODE]]></configKey> - - <description><![CDATA[<p> This code computes a hashCode, and then computes -the remainder of that value modulo another value. Since the hashCode -can be negative, the result of the remainder operation -can also be negative. </p> -<p> Assuming you want to ensure that the result of your computation is nonnegative, -you may need to change your code. -If you know the divisor is a power of 2, -you can use a bitwise and operator instead (i.e., instead of -using <code>x.hashCode()%n</code>, use <code>x.hashCode()&(n-1)</code>. -This is probably faster than computing the remainder as well. -If you don't know that the divisor is a power of 2, take the absolute -value of the result of the remainder operation (i.e., use -<code>Math.abs(x.hashCode()%n)</code> -</p>]]></description> + + </rule> <rule key="INT_BAD_COMPARISON_WITH_NONNEGATIVE_VALUE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Bad comparison of nonnegative value with negative constant]]></name> <configKey><![CDATA[INT_BAD_COMPARISON_WITH_NONNEGATIVE_VALUE]]></configKey> - - <description><![CDATA[<p> This code compares a value that is guaranteed to be non-negative with a negative constant. -</p>]]></description> + + </rule> <rule key="INT_BAD_COMPARISON_WITH_SIGNED_BYTE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Bad comparison of signed byte]]></name> <configKey><![CDATA[INT_BAD_COMPARISON_WITH_SIGNED_BYTE]]></configKey> - - <description><![CDATA[<p> Signed bytes can only have a value in the range -128 to 127. Comparing -a signed byte with a value outside that range is vacuous and likely to be incorrect. -To convert a signed byte <code>b</code> to an unsigned value in the range 0..255, -use <code>0xff & b</code> -</p>]]></description> + + </rule> <rule key="INT_VACUOUS_BIT_OPERATION"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Vacuous bit mask operation on integer value]]></name> <configKey><![CDATA[INT_VACUOUS_BIT_OPERATION]]></configKey> - - <description><![CDATA[<p> This is an integer bit operation (and, or, or exclusive or) that doesn't do any useful work -(e.g., <code>v & 0xffffffff</code>). -</p>]]></description> + </rule> <rule key="INT_VACUOUS_COMPARISON"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Vacuous comparison of integer value]]></name> <configKey><![CDATA[INT_VACUOUS_COMPARISON]]></configKey> - - <description><![CDATA[<p> There is an integer comparison that always returns -the same value (e.g., x <= Integer.MAX_VALUE). -</p>]]></description> + + </rule> <rule key="INT_BAD_REM_BY_1"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Integer remainder modulo 1]]></name> <configKey><![CDATA[INT_BAD_REM_BY_1]]></configKey> - - <description><![CDATA[<p> Any expression (exp % 1) is guaranteed to always return zero. -Did you mean (exp & 1) or (exp % 2) instead? -</p>]]></description> + + </rule> <rule key="BIT_IOR_OF_SIGNED_BYTE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Bitwise OR of signed byte value]]></name> <configKey><![CDATA[BIT_IOR_OF_SIGNED_BYTE]]></configKey> - - <description><![CDATA[<p> Loads a value from a byte array and performs a bitwise OR with -that value. Values loaded from a byte array are sign extended to 32 bits -before any any bitwise operations are performed on the value. -Thus, if <code>b[0]</code> contains the value <code>0xff</code>, and -<code>x</code> is initially 0, then the code -<code>((x << 8) | b[0])</code> will sign extend <code>0xff</code> -to get <code>0xffffffff</code>, and thus give the value -<code>0xffffffff</code> as the result. -</p> - -<p>In particular, the following code for packing a byte array into an int is badly wrong: </p> -<pre> -int result = 0; -for(int i = 0; i < 4; i++) - result = ((result << 8) | b[i]); -</pre> - -<p>The following idiom will work instead: </p> -<pre> -int result = 0; -for(int i = 0; i < 4; i++) - result = ((result << 8) | (b[i] & 0xff)); -</pre>]]></description> + + </rule> <rule key="BIT_ADD_OF_SIGNED_BYTE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Bitwise add of signed byte value]]></name> <configKey><![CDATA[BIT_ADD_OF_SIGNED_BYTE]]></configKey> - - <description><![CDATA[<p> Adds a byte value and a value which is known to the 8 lower bits clear. -Values loaded from a byte array are sign extended to 32 bits -before any any bitwise operations are performed on the value. -Thus, if <code>b[0]</code> contains the value <code>0xff</code>, and -<code>x</code> is initially 0, then the code -<code>((x << 8) + b[0])</code> will sign extend <code>0xff</code> -to get <code>0xffffffff</code>, and thus give the value -<code>0xffffffff</code> as the result. -</p> - -<p>In particular, the following code for packing a byte array into an int is badly wrong: </p> -<pre> -int result = 0; -for(int i = 0; i < 4; i++) - result = ((result << 8) + b[i]); -</pre> - -<p>The following idiom will work instead: </p> -<pre> -int result = 0; -for(int i = 0; i < 4; i++) - result = ((result << 8) + (b[i] & 0xff)); -</pre>]]></description> + + </rule> <rule key="BIT_AND"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Incompatible bit masks]]></name> <configKey><![CDATA[BIT_AND]]></configKey> - - <description><![CDATA[<p> This method compares an expression of the form (e & C) to D, -which will always compare unequal -due to the specific values of constants C and D. -This may indicate a logic error or typo.</p>]]></description> + + </rule> <rule key="BIT_SIGNED_CHECK"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Check for sign of bitwise operation]]></name> <configKey><![CDATA[BIT_SIGNED_CHECK]]></configKey> - - <description><![CDATA[<p> This method compares an expression such as -<pre>((event.detail & SWT.SELECTED) > 0)</pre>. -Using bit arithmetic and then comparing with the greater than operator can -lead to unexpected results (of course depending on the value of -SWT.SELECTED). If SWT.SELECTED is a negative number, this is a candidate -for a bug. Even when SWT.SELECTED is not negative, it seems good practice -to use '!= 0' instead of '> 0'. -</p> -<p> -<em>Boris Bokowski</em> -</p>]]></description> + + </rule> <rule key="BIT_SIGNED_CHECK_HIGH_BIT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Check for sign of bitwise operation]]></name> <configKey><![CDATA[BIT_SIGNED_CHECK_HIGH_BIT]]></configKey> - - <description><![CDATA[<p> This method compares an expression such as -<pre>((event.detail & SWT.SELECTED) > 0)</pre>. -Using bit arithmetic and then comparing with the greater than operator can -lead to unexpected results (of course depending on the value of -SWT.SELECTED). If SWT.SELECTED is a negative number, this is a candidate -for a bug. Even when SWT.SELECTED is not negative, it seems good practice -to use '!= 0' instead of '> 0'. -</p> -<p> -<em>Boris Bokowski</em> -</p>]]></description> + + </rule> <rule key="BIT_AND_ZZ"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Check to see if ((...) & 0) == 0]]></name> <configKey><![CDATA[BIT_AND_ZZ]]></configKey> - - <description><![CDATA[<p> This method compares an expression of the form (e & 0) to 0, -which will always compare equal. -This may indicate a logic error or typo.</p>]]></description> + + </rule> <rule key="BIT_IOR"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Incompatible bit masks]]></name> <configKey><![CDATA[BIT_IOR]]></configKey> - - <description><![CDATA[<p> This method compares an expression of the form (e | C) to D. -which will always compare unequal -due to the specific values of constants C and D. -This may indicate a logic error or typo.</p> -<p> Typically, this bug occurs because the code wants to perform -a membership test in a bit set, but uses the bitwise OR -operator ("|") instead of bitwise AND ("&").</p>]]></description> + </rule> <rule key="LI_LAZY_INIT_STATIC"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Incorrect lazy initialization of static field]]></name> <configKey><![CDATA[LI_LAZY_INIT_STATIC]]></configKey> - - <description><![CDATA[<p> This method contains an unsynchronized lazy initialization of a non-volatile static field. -Because the compiler or processor may reorder instructions, -threads are not guaranteed to see a completely initialized object, -<em>if the method can be called by multiple threads</em>. -You can make the field volatile to correct the problem. -For more information, see the -<a href="http://www.cs.umd.edu/~pugh/java/memoryModel/">Java Memory Model web site</a>. -</p>]]></description> + + </rule> <rule key="LI_LAZY_INIT_UPDATE_STATIC"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Incorrect lazy initialization and update of static field]]></name> <configKey><![CDATA[LI_LAZY_INIT_UPDATE_STATIC]]></configKey> - - <description><![CDATA[<p> This method contains an unsynchronized lazy initialization of a static field. -After the field is set, the object stored into that location is further accessed. -The setting of the field is visible to other threads as soon as it is set. If the -futher accesses in the method that set the field serve to initialize the object, then -you have a <em>very serious</em> multithreading bug, unless something else prevents -any other thread from accessing the stored object until it is fully initialized. -</p>]]></description> + + </rule> <rule key="JLM_JSR166_LOCK_MONITORENTER"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Synchronization performed on java.util.concurrent Lock]]></name> <configKey><![CDATA[JLM_JSR166_LOCK_MONITORENTER]]></configKey> - - <description><![CDATA[<p> This method performs synchronization on an implementation of -<code>java.util.concurrent.locks.Lock</code>. You should use -the <code>lock()</code> and <code>unlock()</code> methods instead. -</p>]]></description> + + </rule> <rule key="UPM_UNCALLED_PRIVATE_METHOD"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Performance - Private method is never called]]></name> <configKey><![CDATA[UPM_UNCALLED_PRIVATE_METHOD]]></configKey> - - <description><![CDATA[<p> This private method is never called. Although it is -possible that the method will be invoked through reflection, -it is more likely that the method is never used, and should be -removed. -</p>]]></description> + + </rule> <rule key="UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Uncallable method defined in anonymous class]]></name> <configKey><![CDATA[UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS]]></configKey> - - <description><![CDATA[<p> This anonymous class defined a method that is not directly invoked and does not override -a method in a superclass. Since methods in other classes cannot directly invoke methods -declared in an anonymous class, it seems that this method is uncallable. The method -might simply be dead code, but it is also possible that the method is intended to -override a method declared in a superclass, and due to an typo or other error the method does not, -in fact, override the method it is intended to. -</p>]]></description> + + </rule> <rule key="ODR_OPEN_DATABASE_RESOURCE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Method may fail to close database resource]]></name> <configKey><![CDATA[ODR_OPEN_DATABASE_RESOURCE]]></configKey> - - <description><![CDATA[<p> The method creates a database resource (such as a database connection -or row set), does not assign it to any -fields, pass it to other methods, or return it, and does not appear to close -the object on all paths out of the method. Failure to -close database resources on all paths out of a method may -result in poor performance, and could cause the application to -have problems communicating with the database. -</p>]]></description> + + </rule> <rule key="ODR_OPEN_DATABASE_RESOURCE_EXCEPTION_PATH"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Method may fail to close database resource on exception]]></name> <configKey><![CDATA[ODR_OPEN_DATABASE_RESOURCE_EXCEPTION_PATH]]></configKey> - - <description><![CDATA[<p> The method creates a database resource (such as a database connection -or row set), does not assign it to any -fields, pass it to other methods, or return it, and does not appear to close -the object on all exception paths out of the method. Failure to -close database resources on all paths out of a method may -result in poor performance, and could cause the application to -have problems communicating with the database.</p>]]></description> + + </rule> <rule key="SBSC_USE_STRINGBUFFER_CONCATENATION"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Performance - Method concatenates strings using + in a loop]]></name> <configKey><![CDATA[SBSC_USE_STRINGBUFFER_CONCATENATION]]></configKey> - - <description><![CDATA[<p> The method seems to be building a String using concatenation in a loop. -In each iteration, the String is converted to a StringBuffer/StringBuilder, - appended to, and converted back to a String. - This can lead to a cost quadratic in the number of iterations, - as the growing string is recopied in each iteration. </p> - -<p>Better performance can be obtained by using -a StringBuffer (or StringBuilder in Java 1.5) explicitly.</p> - -<p> For example:</p> -<pre> - // This is bad - String s = ""; - for (int i = 0; i < field.length; ++i) { - s = s + field[i]; - } - - // This is better - StringBuffer buf = new StringBuffer(); - for (int i = 0; i < field.length; ++i) { - buf.append(field[i]); - } - String s = buf.toString(); -</pre>]]></description> + + </rule> <rule key="ITA_INEFFICIENT_TO_ARRAY"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Performance - Method uses toArray() with zero-length array argument]]></name> <configKey><![CDATA[ITA_INEFFICIENT_TO_ARRAY]]></configKey> - - <description><![CDATA[<p> This method uses the toArray() method of a collection derived class, and passes -in a zero-length prototype array argument. It is more efficient to use -<code>myCollection.toArray(new Foo[myCollection.size()])</code> -If the array passed in is big enough to store all of the -elements of the collection, then it is populated and returned -directly. This avoids the need to create a second array -(by reflection) to return as the result.</p>]]></description> + + </rule> <rule key="IJU_ASSERT_METHOD_INVOKED_FROM_RUN_METHOD"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - JUnit assertion in run method will not be noticed by JUnit]]></name> <configKey><![CDATA[IJU_ASSERT_METHOD_INVOKED_FROM_RUN_METHOD]]></configKey> - - <description><![CDATA[<p> A JUnit assertion is performed in a run method. Failed JUnit assertions -just result in exceptions being thrown. -Thus, if this exception occurs in a thread other than the thread that invokes -the test method, the exception will terminate the thread but not result -in the test failing. -</p>]]></description> + + </rule> <rule key="IJU_SETUP_NO_SUPER"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - TestCase defines setUp that doesn't call super.setUp()]]></name> <configKey><![CDATA[IJU_SETUP_NO_SUPER]]></configKey> - - <description><![CDATA[<p> Class is a JUnit TestCase and implements the setUp method. The setUp method should call -super.setUp(), but doesn't.</p>]]></description> + + </rule> <rule key="IJU_TEARDOWN_NO_SUPER"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - TestCase defines tearDown that doesn't call super.tearDown()]]></name> <configKey><![CDATA[IJU_TEARDOWN_NO_SUPER]]></configKey> - - <description><![CDATA[<p> Class is a JUnit TestCase and implements the tearDown method. The tearDown method should call -super.tearDown(), but doesn't.</p>]]></description> + + </rule> <rule key="IJU_SUITE_NOT_STATIC"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - TestCase implements a non-static suite method ]]></name> <configKey><![CDATA[IJU_SUITE_NOT_STATIC]]></configKey> - - <description><![CDATA[<p> Class is a JUnit TestCase and implements the suite() method. - The suite method should be declared as being static, but isn't.</p>]]></description> + + </rule> <rule key="IJU_BAD_SUITE_METHOD"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - TestCase declares a bad suite method ]]></name> <configKey><![CDATA[IJU_BAD_SUITE_METHOD]]></configKey> - - <description><![CDATA[<p> Class is a JUnit TestCase and defines a suite() method. -However, the suite method needs to be declared as either -<pre>public static junit.framework.Test suite()</pre> -or -<pre>public static junit.framework.TestSuite suite()</pre> -</p>]]></description> + + </rule> <rule key="IJU_NO_TESTS"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - TestCase has no tests]]></name> <configKey><![CDATA[IJU_NO_TESTS]]></configKey> - - <description><![CDATA[<p> Class is a JUnit TestCase but has not implemented any test methods</p>]]></description> + + </rule> <rule key="BOA_BADLY_OVERRIDDEN_ADAPTER"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Class overrides a method implemented in super class Adapter wrongly]]></name> <configKey><![CDATA[BOA_BADLY_OVERRIDDEN_ADAPTER]]></configKey> - - <description><![CDATA[<p> This method overrides a method found in a parent class, where that class is an Adapter that implements -a listener defined in the java.awt.event or javax.swing.event package. As a result, this method will not -get called when the event occurs.</p>]]></description> + + </rule> <rule key="SQL_BAD_RESULTSET_ACCESS"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Method attempts to access a result set field with index 0]]></name> <configKey><![CDATA[SQL_BAD_RESULTSET_ACCESS]]></configKey> - - <description><![CDATA[<p> A call to getXXX or updateXXX methods of a result set was made where the -field index is 0. As ResultSet fields start at index 1, this is always a mistake.</p>]]></description> + + </rule> <rule key="SQL_BAD_PREPARED_STATEMENT_ACCESS"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Method attempts to access a prepared statement parameter with index 0]]></name> <configKey><![CDATA[SQL_BAD_PREPARED_STATEMENT_ACCESS]]></configKey> - - <description><![CDATA[<p> A call to a setXXX method of a prepared statement was made where the -parameter index is 0. As parameter indexes start at index 1, this is always a mistake.</p>]]></description> + + </rule> <rule key="SIO_SUPERFLUOUS_INSTANCEOF"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Unnecessary type check done using instanceof operator]]></name> <configKey><![CDATA[SIO_SUPERFLUOUS_INSTANCEOF]]></configKey> - - <description><![CDATA[<p> Type check performed using the instanceof operator where it can be statically determined whether the object -is of the type requested. </p>]]></description> + + </rule> <rule key="EC_ARRAY_AND_NONARRAY"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - equals() used to compare array and nonarray]]></name> <configKey><![CDATA[EC_ARRAY_AND_NONARRAY]]></configKey> - - <description><![CDATA[<p> -This method invokes the .equals(Object o) to compare an array and a reference that doesn't seem -to be an array. If things being compared are of different types, they are guaranteed to be unequal -and the comparison is almost certainly an error. Even if they are both arrays, the equals method -on arrays only determines of the two arrays are the same object. -To compare the -contents of the arrays, use java.util.Arrays.equals(Object[], Object[]). -</p>]]></description> + + </rule> <rule key="EC_BAD_ARRAY_COMPARE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Invocation of equals() on an array, which is equivalent to ==]]></name> <configKey><![CDATA[EC_BAD_ARRAY_COMPARE]]></configKey> - - <description><![CDATA[<p> -This method invokes the .equals(Object o) method on an array. Since arrays do not override the equals -method of Object, calling equals on an array is the same as comparing their addresses. To compare the -contents of the arrays, use java.util.Arrays.equals(Object[], Object[]). -</p>]]></description> + + </rule> <rule key="STI_INTERRUPTED_ON_CURRENTTHREAD"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Unneeded use of currentThread() call, to call interrupted() ]]></name> <configKey><![CDATA[STI_INTERRUPTED_ON_CURRENTTHREAD]]></configKey> - - <description><![CDATA[<p> -This method invokes the Thread.currentThread() call, just to call the interrupted() method. As interrupted() is a -static method, is more simple and clear to use Thread.interrupted(). -</p>]]></description> + + </rule> <rule key="STI_INTERRUPTED_ON_UNKNOWNTHREAD"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Static Thread.interrupted() method invoked on thread instance]]></name> <configKey><![CDATA[STI_INTERRUPTED_ON_UNKNOWNTHREAD]]></configKey> - - <description><![CDATA[<p> -This method invokes the Thread.interrupted() method on a Thread object that appears to be a Thread object that is -not the current thread. As the interrupted() method is static, the interrupted method will be called on a different -object than the one the author intended. -</p>]]></description> + + </rule> <rule key="IP_PARAMETER_IS_DEAD_BUT_OVERWRITTEN"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - A parameter is dead upon entry to a method but overwritten]]></name> <configKey><![CDATA[IP_PARAMETER_IS_DEAD_BUT_OVERWRITTEN]]></configKey> - - <description><![CDATA[<p> -The initial value of this parameter is ignored, and the parameter -is overwritten here. This often indicates a mistaken belief that -the write to the parameter will be conveyed back to -the caller. -</p>]]></description> + + </rule> <rule key="DLS_DEAD_LOCAL_STORE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Dead store to local variable]]></name> <configKey><![CDATA[DLS_DEAD_LOCAL_STORE]]></configKey> - - <description><![CDATA[<p> -This instruction assigns a value to a local variable, -but the value is not read or used in any subsequent instruction. -Often, this indicates an error, because the value computed is never -used. -</p> -<p> -Note that Sun's javac compiler often generates dead stores for -final local variables. Because FindBugs is a bytecode-based tool, -there is no easy way to eliminate these false positives. -</p>]]></description> + + </rule> <rule key="DLS_DEAD_LOCAL_STORE_IN_RETURN"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Useless assignment in return statement]]></name> <configKey><![CDATA[DLS_DEAD_LOCAL_STORE_IN_RETURN]]></configKey> - - <description><![CDATA[<p> -This statement assigns to a local variable in a return statement. This assignment -has effect. Please verify that this statement does the right thing. -</p>]]></description> + + </rule> <rule key="DLS_DEAD_STORE_OF_CLASS_LITERAL"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Dead store of class literal]]></name> <configKey><![CDATA[DLS_DEAD_STORE_OF_CLASS_LITERAL]]></configKey> - - <description><![CDATA[<p> -This instruction assigns a class literal to a variable and then never uses it. -<a href="//java.sun.com/j2se/1.5.0/compatibility.html#literal">The behavior of this differs in Java 1.4 and in Java 5.</a> -In Java 1.4 and earlier, a reference to <code>Foo.class</code> would force the static initializer -for <code>Foo</code> to be executed, if it has not been executed already. -In Java 5 and later, it does not. -</p> -<p>See Sun's <a href="//java.sun.com/j2se/1.5.0/compatibility.html#literal">article on Java SE compatibility</a> -for more details and examples, and suggestions on how to force class initialization in Java 5. -</p>]]></description> + + </rule> <rule key="DLS_DEAD_LOCAL_STORE_OF_NULL"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Dead store of null to local variable]]></name> <configKey><![CDATA[DLS_DEAD_LOCAL_STORE_OF_NULL]]></configKey> - - <description><![CDATA[<p>The code stores null into a local variable, and the stored value is not -read. This store may have been introduced to assist the garbage collector, but -as of Java SE 6.0, this is no longer needed or useful. -</p>]]></description> + + </rule> <rule key="MF_METHOD_MASKS_FIELD"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Method defines a variable that obscures a field]]></name> <configKey><![CDATA[MF_METHOD_MASKS_FIELD]]></configKey> - - <description><![CDATA[<p> This method defines a local variable with the same name as a field -in this class or a superclass. This may cause the method to -read an uninitialized value from the field, leave the field uninitialized, -or both.</p>]]></description> + + </rule> <rule key="MF_CLASS_MASKS_FIELD"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Class defines field that masks a superclass field]]></name> <configKey><![CDATA[MF_CLASS_MASKS_FIELD]]></configKey> - - <description><![CDATA[<p> This class defines a field with the same name as a visible -instance field in a superclass. This is confusing, and -may indicate an error if methods update or access one of -the fields when they wanted the other.</p>]]></description> + + </rule> <rule key="WMI_WRONG_MAP_ITERATOR"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Performance - Inefficient use of keySet iterator instead of entrySet iterator]]></name> <configKey><![CDATA[WMI_WRONG_MAP_ITERATOR]]></configKey> - - <description><![CDATA[<p> This method accesses the value of a Map entry, using a key that was retrieved from -a keySet iterator. It is more efficient to use an iterator on the entrySet of the map, to avoid the -Map.get(key) lookup.</p>]]></description> + + </rule> <rule key="ISC_INSTANTIATE_STATIC_CLASS"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Bad practice - Needless instantiation of class that only supplies static methods]]></name> <configKey><![CDATA[ISC_INSTANTIATE_STATIC_CLASS]]></configKey> - - <description><![CDATA[<p> This class allocates an object that is based on a class that only supplies static methods. This object -does not need to be created, just access the static methods directly using the class name as a qualifier.</p>]]></description> + + </rule> <rule key="REC_CATCH_EXCEPTION"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Dodgy - Exception is caught when Exception is not thrown]]></name> <configKey><![CDATA[REC_CATCH_EXCEPTION]]></configKey> - - <description><![CDATA[<p> - This method uses a try-catch block that catches Exception objects, but Exception is not - thrown within the try block, and RuntimeException is not explicitly caught. It is a common bug pattern to - say try { ... } catch (Exception e) { something } as a shorthand for catching a number of types of exception - each of whose catch blocks is identical, but this construct also accidentally catches RuntimeException as well, - masking potential bugs. - </p>]]></description> + + </rule> <rule key="FE_TEST_IF_EQUAL_TO_NOT_A_NUMBER"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Doomed test for equality to NaN]]></name> <configKey><![CDATA[FE_TEST_IF_EQUAL_TO_NOT_A_NUMBER]]></configKey> - - <description><![CDATA[<p> - This code checks to see if a floating point value is equal to the special - Not A Number value (e.g., <code>if (x == Double.NaN)</code>). However, - because of the special semantics of <code>NaN</code>, no value - is equal to <code>Nan</code>, including <code>NaN</code>. Thus, - <code>x == Double.NaN</code> always evaluates to false. - - To check to see if a value contained in <code>x</code> - is the special Not A Number value, use - <code>Double.isNaN(x)</code> (or <code>Float.isNaN(x)</code> if - <code>x</code> is floating point precision). - </p>]]></description> + + </rule> <rule key="FE_FLOATING_POINT_EQUALITY"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Test for floating point equality]]></name> <configKey><![CDATA[FE_FLOATING_POINT_EQUALITY]]></configKey> - - <description><![CDATA[<p> - This operation compares two floating point values for equality. - Because floating point calculations may involve rounding, - calculated float and double values may not be accurate. - For values that must be precise, such as monetary values, - consider using a fixed-precision type such as BigDecimal. - For values that need not be precise, consider comparing for equality - within some range, for example: - <code>if ( Math.abs(x - y) < .0000001 )</code>. - See the Java Language Specification, section 4.2.4. - </p>]]></description> + + </rule> <rule key="UM_UNNECESSARY_MATH"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Performance - Method calls static Math class method on a constant value]]></name> <configKey><![CDATA[UM_UNNECESSARY_MATH]]></configKey> - - <description><![CDATA[<p> This method uses a static method from java.lang.Math on a constant value. This method's -result in this case, can be determined statically, and is faster and sometimes more accurate to -just use the constant. Methods detected are: -</p> -<table> -<tr> - <th>Method</th> <th>Parameter</th> -</tr> -<tr> - <td>abs</td> <td>-any-</td> -</tr> -<tr> - <td>acos</td> <td>0.0 or 1.0</td> -</tr> -<tr> - <td>asin</td> <td>0.0 or 1.0</td> -</tr> -<tr> - <td>atan</td> <td>0.0 or 1.0</td> -</tr> -<tr> - <td>atan2</td> <td>0.0</td> -</tr> -<tr> - <td>cbrt</td> <td>0.0 or 1.0</td> -</tr> -<tr> - <td>ceil</td> <td>-any-</td> -</tr> -<tr> - <td>cos</td> <td>0.0</td> -</tr> -<tr> - <td>cosh</td> <td>0.0</td> -</tr> -<tr> - <td>exp</td> <td>0.0 or 1.0</td> -</tr> -<tr> - <td>expm1</td> <td>0.0</td> -</tr> -<tr> - <td>floor</td> <td>-any-</td> -</tr> -<tr> - <td>log</td> <td>0.0 or 1.0</td> -</tr> -<tr> - <td>log10</td> <td>0.0 or 1.0</td> -</tr> -<tr> - <td>rint</td> <td>-any-</td> -</tr> -<tr> - <td>round</td> <td>-any-</td> -</tr> -<tr> - <td>sin</td> <td>0.0</td> -</tr> -<tr> - <td>sinh</td> <td>0.0</td> -</tr> -<tr> - <td>sqrt</td> <td>0.0 or 1.0</td> -</tr> -<tr> - <td>tan</td> <td>0.0</td> -</tr> -<tr> - <td>tanh</td> <td>0.0</td> -</tr> -<tr> - <td>toDegrees</td> <td>0.0 or 1.0</td> -</tr> -<tr> - <td>toRadians</td> <td>0.0</td> -</tr> -</table>]]></description> + + </rule> <rule key="RI_REDUNDANT_INTERFACES"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Dodgy - Class implements same interface as superclass]]></name> <configKey><![CDATA[RI_REDUNDANT_INTERFACES]]></configKey> - - <description><![CDATA[<p> - This class declares that it implements an interface that is also implemented by a superclass. - This is redundant because once a superclass implements an interface, all subclasses by default also - implement this interface. It may point out that the inheritance hierarchy has changed since - this class was created, and consideration should be given to the ownership of - the interface's implementation. - </p>]]></description> + + </rule> <rule key="MTIA_SUSPECT_STRUTS_INSTANCE_FIELD"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Class extends Struts Action class and uses instance variables]]></name> <configKey><![CDATA[MTIA_SUSPECT_STRUTS_INSTANCE_FIELD]]></configKey> - - <description><![CDATA[<p> - This class extends from a Struts Action class, and uses an instance member variable. Since only - one instance of a struts Action class is created by the Struts framework, and used in a - multithreaded way, this paradigm is highly discouraged and most likely problematic. Consider - only using method local variables. Only instance fields that are written outside of a monitor - are reported. - </p>]]></description> + + </rule> <rule key="MTIA_SUSPECT_SERVLET_INSTANCE_FIELD"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Class extends Servlet class and uses instance variables]]></name> <configKey><![CDATA[MTIA_SUSPECT_SERVLET_INSTANCE_FIELD]]></configKey> - - <description><![CDATA[<p> - This class extends from a Servlet class, and uses an instance member variable. Since only - one instance of a Servlet class is created by the J2EE framework, and used in a - multithreaded way, this paradigm is highly discouraged and most likely problematic. Consider - only using method local variables. - </p>]]></description> + + </rule> <rule key="PS_PUBLIC_SEMAPHORES"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Class exposes synchronization and semaphores in its public interface]]></name> <configKey><![CDATA[PS_PUBLIC_SEMAPHORES]]></configKey> - - <description><![CDATA[<p> - This class uses synchronization along with wait(), notify() or notifyAll() on itself (the this - reference). Client classes that use this class, may, in addition, use an instance of this class - as a synchronizing object. Because two classes are using the same object for synchronization, - Multithread correctness is suspect. You should not synchronize nor call semaphore methods on - a public reference. Consider using a internal private member variable to control synchronization. - </p>]]></description> + + </rule> <rule key="ICAST_INTEGER_MULTIPLY_CAST_TO_LONG"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Result of integer multiplication cast to long]]></name> <configKey><![CDATA[ICAST_INTEGER_MULTIPLY_CAST_TO_LONG]]></configKey> - - <description><![CDATA[<p> -This code performs integer multiply and then converts the result to a long, -as in: -<code> -<pre> - long convertDaysToMilliseconds(int days) { return 1000*3600*24*days; } -</pre></code> -If the multiplication is done using long arithmetic, you can avoid -the possibility that the result will overflow. For example, you -could fix the above code to: -<code> -<pre> - long convertDaysToMilliseconds(int days) { return 1000L*3600*24*days; } -</pre></code> -or -<code> -<pre> - static final long MILLISECONDS_PER_DAY = 24L*3600*1000; - long convertDaysToMilliseconds(int days) { return days * MILLISECONDS_PER_DAY; } -</pre></code> -</p>]]></description> + + </rule> <rule key="ICAST_INT_CAST_TO_FLOAT_PASSED_TO_ROUND"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - int value cast to float and then passed to Math.round]]></name> <configKey><![CDATA[ICAST_INT_CAST_TO_FLOAT_PASSED_TO_ROUND]]></configKey> - - <description><![CDATA[<p> -This code converts an int value to a float precision -floating point number and then -passing the result to the Math.round() function, which returns the int/long closest -to the argument. This operation should always be a no-op, -since the converting an integer to a float should give a number with no fractional part. -It is likely that the operation that generated the value to be passed -to Math.round was intended to be performed using -floating point arithmetic. -</p>]]></description> + + </rule> <rule key="ICAST_INT_CAST_TO_DOUBLE_PASSED_TO_CEIL"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - int value cast to double and then passed to Math.ceil]]></name> <configKey><![CDATA[ICAST_INT_CAST_TO_DOUBLE_PASSED_TO_CEIL]]></configKey> - - <description><![CDATA[<p> -This code converts an int value to a double precision -floating point number and then -passing the result to the Math.ceil() function, which rounds a double to -the next higher integer value. This operation should always be a no-op, -since the converting an integer to a double should give a number with no fractional part. -It is likely that the operation that generated the value to be passed -to Math.ceil was intended to be performed using double precision -floating point arithmetic. -</p>]]></description> + + </rule> <rule key="ICAST_IDIV_CAST_TO_DOUBLE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - int division result cast to double or float]]></name> <configKey><![CDATA[ICAST_IDIV_CAST_TO_DOUBLE]]></configKey> - - <description><![CDATA[<p> -This code casts the result of an integer division operation to double or -float. -Doing division on integers truncates the result -to the integer value closest to zero. The fact that the result -was cast to double suggests that this precision should have been retained. -What was probably meant was to cast one or both of the operands to -double <em>before</em> performing the division. Here is an example: -</p> -<blockquote> -<pre> -int x = 2; -int y = 5; -// Wrong: yields result 0.0 -double value1 = x / y; - -// Right: yields result 0.4 -double value2 = x / (double) y; -</pre> -</blockquote>]]></description> + + </rule> <rule key="J2EE_STORE_OF_NON_SERIALIZABLE_OBJECT_INTO_SESSION"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Store of non serializable object into HttpSession]]></name> <configKey><![CDATA[J2EE_STORE_OF_NON_SERIALIZABLE_OBJECT_INTO_SESSION]]></configKey> - - <description><![CDATA[<p> -This code seems to be storing a non-serializable object into an HttpSession. -If this session is passivated or migrated, an error will result. -</p>]]></description> + + </rule> <rule key="DMI_NONSERIALIZABLE_OBJECT_WRITTEN"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Non serializable object written to ObjectOutput]]></name> <configKey><![CDATA[DMI_NONSERIALIZABLE_OBJECT_WRITTEN]]></configKey> - - <description><![CDATA[<p> -This code seems to be passing a non-serializable object to the ObjectOutput.writeObject method. -If the object is, indeed, non-serializable, an error will result. -</p>]]></description> + + </rule> <rule key="VA_FORMAT_STRING_NO_PREVIOUS_ARGUMENT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - No previous argument for format string]]></name> <configKey><![CDATA[VA_FORMAT_STRING_NO_PREVIOUS_ARGUMENT]]></configKey> - - <description><![CDATA[<p> -The format string specifies a relative index to request that the argument for the previous format specifier -be reused. However, there is no previous argument. -For example, -</p> -<p><code>formatter.format("%<s %s", "a", "b")</code> -</p> -<p>would throw a MissingFormatArgumentException when executed. -</p>]]></description> + + </rule> <rule key="VA_FORMAT_STRING_BAD_CONVERSION"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - The type of a supplied argument doesn't match format specifier]]></name> <configKey><![CDATA[VA_FORMAT_STRING_BAD_CONVERSION]]></configKey> - - <description><![CDATA[<p> -One of the arguments is uncompatible with the corresponding format string specifier. -As a result, this will generate a runtime exception when executed. -For example, <code>String.format("%d", "1")</code> will generate an exception, since -the String "1" is incompatible with the format specifier %d. -</p>]]></description> + + </rule> <rule key="VA_FORMAT_STRING_BAD_CONVERSION_TO_BOOLEAN"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Dodgy - Non-Boolean argument formatted using %b format specifier]]></name> <configKey><![CDATA[VA_FORMAT_STRING_BAD_CONVERSION_TO_BOOLEAN]]></configKey> - - <description><![CDATA[<p> -An argument not of type Boolean is being formatted with a %b format specifier. This won't throw an -exception; instead, it will print true for any nonnull value, and false for null. -This feature of format strings is strange, and may not be what you intended. -</p>]]></description> + + </rule> <rule key="VA_FORMAT_STRING_BAD_CONVERSION_FROM_ARRAY"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - Array formatted in useless way using format string]]></name> <configKey><![CDATA[VA_FORMAT_STRING_BAD_CONVERSION_FROM_ARRAY]]></configKey> - - <description><![CDATA[<p> -One of the arguments being formatted with a format string is an array. This will be formatted -using a fairly useless format, such as [I@304282, which doesn't actually show the contents -of the array. -Consider wrapping the array using <code>Arrays.asList(...)</code> before handling it off to a formatted. -</p>]]></description> + + </rule> <rule key="VA_FORMAT_STRING_ARG_MISMATCH"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name> <![CDATA[Correctness - Number of format-string arguments does not correspond to number of placeholders]]></name> <configKey><![CDATA[VA_FORMAT_STRING_ARG_MISMATCH]]></configKey> - - <description><![CDATA[<p> -A format-string method with a variable number of arguments is called, -but the number of arguments passed does not match with the number of -% placeholders in the format string. This is probably not what the -author intended. -</p>]]></description> + + </rule> <rule key="VA_FORMAT_STRING_EXTRA_ARGUMENTS_PASSED"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Correctness - More arguments are passed that are actually used in the format string]]></name> <configKey><![CDATA[VA_FORMAT_STRING_EXTRA_ARGUMENTS_PASSED]]></configKey> - - <description><![CDATA[<p> -A format-string method with a variable number of arguments is called, -but more arguments are passed than are actually used by the format string. -This won't cause a runtime exception, but the code may be silently omitting -information that was intended to be included in the formatted string. -</p>]]></description> + + </rule> <rule key="VA_FORMAT_STRING_ILLEGAL"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Illegal format string]]></name> <configKey><![CDATA[VA_FORMAT_STRING_ILLEGAL]]></configKey> - - <description><![CDATA[<p> -The format string is syntactically invalid, -and a runtime exception will occur when -this statement is executed. -</p>]]></description> + + </rule> <rule key="VA_FORMAT_STRING_MISSING_ARGUMENT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Format string references missing argument]]></name> <configKey><![CDATA[VA_FORMAT_STRING_MISSING_ARGUMENT]]></configKey> - - <description><![CDATA[<p> -Not enough arguments are passed to satisfy a placeholder in the format string. -A runtime exception will occur when -this statement is executed. -</p>]]></description> + + </rule> <rule key="VA_FORMAT_STRING_BAD_ARGUMENT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Format string placeholder incompatible with passed argument]]></name> <configKey><![CDATA[VA_FORMAT_STRING_BAD_ARGUMENT]]></configKey> - - <description><![CDATA[<p> -The format string placeholder is incompatible with the corresponding -argument. For example, -<code> - System.out.println("%d\n", "hello"); -</code> -<p>The %d placeholder requires a numeric argument, but a string value is -passed instead. -A runtime exception will occur when -this statement is executed. -</p>]]></description> + + </rule> <rule key="VA_PRIMITIVE_ARRAY_PASSED_TO_OBJECT_VARARG"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name> <![CDATA[Correctness - Primitive array passed to function expecting a variable number of object arguments]]></name> <configKey><![CDATA[VA_PRIMITIVE_ARRAY_PASSED_TO_OBJECT_VARARG]]></configKey> - - <description><![CDATA[<p> -This code passes a primitive array to a function that takes a variable number of object arguments. -This creates an array of length one to hold the primitive array and passes it to the function. -</p>]]></description> + + </rule> <rule key="BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Equals method should not assume anything about the type of its argument]]></name> <configKey><![CDATA[BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS]]></configKey> - - <description><![CDATA[<p> -The <code>equals(Object o)</code> method shouldn't make any assumptions -about the type of <code>o</code>. It should simply return -false if <code>o</code> is not the same type as <code>this</code>. -</p>]]></description> + + </rule> <rule key="BC_BAD_CAST_TO_ABSTRACT_COLLECTION"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name><![CDATA[Dodgy - Questionable cast to abstract collection ]]></name> <configKey><![CDATA[BC_BAD_CAST_TO_ABSTRACT_COLLECTION]]></configKey> - - <description><![CDATA[<p> -This code casts a Collection to an abstract collection -(such as <code>List</code>, <code>Set</code>, or <code>Map</code>). -Ensure that you are guaranteed that the object is of the type -you are casting to. If all you need is to be able -to iterate through a collection, you don't need to cast it to a Set or List. -</p>]]></description> + + </rule> <rule key="BC_IMPOSSIBLE_CAST"> -<priority>BLOCKER</priority> + <priority>BLOCKER</priority> <name><![CDATA[Correctness - Impossible cast]]></name> <configKey><![CDATA[BC_IMPOSSIBLE_CAST]]></configKey> - - <description><![CDATA[<p> -This cast will always throw a ClassCastException. -</p>]]></description> + + </rule> <rule key="NP_NULL_INSTANCEOF"> -<priority>BLOCKER</priority> + <priority>BLOCKER</priority> <name><![CDATA[Correctness - A known null value is checked to see if it is an instance of a type]]></name> <configKey><![CDATA[NP_NULL_INSTANCEOF]]></configKey> - - <description><![CDATA[<p> -This instanceof test will always return false, since the value being checked is guaranteed to be null. -Although this is safe, make sure it isn't -an indication of some misunderstanding or some other logic error. -</p>]]></description> + + </rule> <rule key="BC_IMPOSSIBLE_INSTANCEOF"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - instanceof will always return false]]></name> <configKey><![CDATA[BC_IMPOSSIBLE_INSTANCEOF]]></configKey> - - <description><![CDATA[<p> -This instanceof test will always return false. Although this is safe, make sure it isn't -an indication of some misunderstanding or some other logic error. -</p>]]></description> + + </rule> <rule key="BC_VACUOUS_INSTANCEOF"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - instanceof will always return true]]></name> <configKey><![CDATA[BC_VACUOUS_INSTANCEOF]]></configKey> - - <description><![CDATA[<p> -This instanceof test will always return true (unless the value being tested is null). -Although this is safe, make sure it isn't -an indication of some misunderstanding or some other logic error. -If you really want to test the value for being null, perhaps it would be clearer to do -better to do a null test rather than an instanceof test. -</p>]]></description> + + </rule> <rule key="BC_UNCONFIRMED_CAST"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Unchecked/unconfirmed cast]]></name> <configKey><![CDATA[BC_UNCONFIRMED_CAST]]></configKey> - - <description><![CDATA[<p> -This cast is unchecked, and not all instances of the type casted from can be cast to -the type it is being cast to. Ensure that your program logic ensures that this -cast will not fail. -</p>]]></description> + + </rule> <rule key="BC_BAD_CAST_TO_CONCRETE_COLLECTION"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Questionable cast to concrete collection]]></name> <configKey><![CDATA[BC_BAD_CAST_TO_CONCRETE_COLLECTION]]></configKey> - - <description><![CDATA[<p> -This code casts an abstract collection (such as a Collection, List, or Set) -to a specific concrete implementation (such as an ArrayList or HashSet). -This might not be correct, and it may make your code fragile, since -it makes it harder to switch to other concrete implementations at a future -point. Unless you have a particular reason to do so, just use the abstract -collection class. -</p>]]></description> + + </rule> <rule key="RE_POSSIBLE_UNINTENDED_PATTERN"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - "." used for regular expression]]></name> <configKey><![CDATA[RE_POSSIBLE_UNINTENDED_PATTERN]]></configKey> - - <description><![CDATA[<p> -A String function is being invoked and "." is being passed -to a parameter that takes a regular expression as an argument. Is this what you intended? -For example -s.replaceAll(".", "/") will return a String in which <em>every</em> -character has been replaced by a / character. -</p>]]></description> + + </rule> <rule key="RE_BAD_SYNTAX_FOR_REGULAR_EXPRESSION"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Invalid syntax for regular expression]]></name> <configKey><![CDATA[RE_BAD_SYNTAX_FOR_REGULAR_EXPRESSION]]></configKey> - - <description><![CDATA[<p> -The code here uses a regular expression that is invalid according to the syntax -for regular expressions. This statement will throw a PatternSyntaxException when -executed. -</p>]]></description> + + </rule> <rule key="RE_CANT_USE_FILE_SEPARATOR_AS_REGULAR_EXPRESSION"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - File.separator used for regular expression]]></name> <configKey><![CDATA[RE_CANT_USE_FILE_SEPARATOR_AS_REGULAR_EXPRESSION]]></configKey> - - <description><![CDATA[<p> -The code here uses <code>File.separator</code> -where a regular expression is required. This will fail on Windows -platforms, where the <code>File.separator</code> is a backslash, which is interpreted in a -regular expression as an escape character. Amoung other options, you can just use -<code>File.separatorChar=='\\' & "\\\\" : File.separator</code> instead of -<code>File.separator</code> -</p>]]></description> + </rule> <rule key="DLS_OVERWRITTEN_INCREMENT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Overwritten increment]]></name> <configKey><![CDATA[DLS_OVERWRITTEN_INCREMENT]]></configKey> - - <description><![CDATA[<p> -The code performs an increment operation (e.g., <code>i++</code>) and then -immediately overwrites it. For example, <code>i = i++</code> immediately -overwrites the incremented value with the original value. -</p>]]></description> + + </rule> <rule key="ICAST_QUESTIONABLE_UNSIGNED_RIGHT_SHIFT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Unsigned right shift cast to short/byte]]></name> <configKey><![CDATA[ICAST_QUESTIONABLE_UNSIGNED_RIGHT_SHIFT]]></configKey> - - <description><![CDATA[<p> -The code performs an unsigned right shift, whose result is then -cast to a short or byte, which discards the upper bits of the result. -Since the upper bits are discarded, there may be no difference between -a signed and unsigned right shift (depending upon the size of the shift). -</p>]]></description> + + </rule> <rule key="ICAST_BAD_SHIFT_AMOUNT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Integer shift by an amount not in the range 0..31]]></name> <configKey><![CDATA[ICAST_BAD_SHIFT_AMOUNT]]></configKey> - - <description><![CDATA[<p> -The code performs an integer shift by a constant amount outside -the range 0..31. -The effect of this is to use the lower 5 bits of the integer -value to decide how much to shift by. This probably isn't want was expected, -and it at least confusing. -</p>]]></description> + + </rule> <rule key="IM_MULTIPLYING_RESULT_OF_IREM"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Integer multiply of result of integer remainder]]></name> <configKey><![CDATA[IM_MULTIPLYING_RESULT_OF_IREM]]></configKey> - - <description><![CDATA[<p> -The code multiplies the result of an integer remaining by an integer constant. -Be sure you don't have your operator precedence confused. For example -i % 60 * 1000 is (i % 60) * 1000, not i % (60 * 1000). -</p>]]></description> + + </rule> <rule key="DMI_INVOKING_HASHCODE_ON_ARRAY"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Invocation of hashCode on an array]]></name> <configKey><![CDATA[DMI_INVOKING_HASHCODE_ON_ARRAY]]></configKey> - - <description><![CDATA[<p> -The code invokes hashCode on an array. Calling hashCode on -an array returns the same value as System.identityHashCode, and ingores -the contents and length of the array. If you need a hashCode that -depends on the contents of an array <code>a</code>, -use <code>java.util.Arrays.hashCode(a)</code>. -</p>]]></description> + </rule> <rule key="DMI_INVOKING_TOSTRING_ON_ARRAY"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Invocation of toString on an array]]></name> <configKey><![CDATA[DMI_INVOKING_TOSTRING_ON_ARRAY]]></configKey> - - <description><![CDATA[<p> -The code invokes toString on an array, which will generate a fairly useless result -such as [C@16f0472. Consider using Arrays.toString to convert the array into a readable -String that gives the contents of the array. See Programming Puzzlers, chapter 3, puzzle 12. -</p>]]></description> + + </rule> <rule key="DMI_INVOKING_TOSTRING_ON_ANONYMOUS_ARRAY"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Invocation of toString on an array]]></name> <configKey><![CDATA[DMI_INVOKING_TOSTRING_ON_ANONYMOUS_ARRAY]]></configKey> - - <description><![CDATA[<p> -The code invokes toString on an (anonymous) array. Calling toString on an array generates a fairly useless result -such as [C@16f0472. Consider using Arrays.toString to convert the array into a readable -String that gives the contents of the array. See Programming Puzzlers, chapter 3, puzzle 12. -</p>]]></description> + + </rule> <rule key="IM_AVERAGE_COMPUTATION_COULD_OVERFLOW"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Computation of average could overflow]]></name> <configKey><![CDATA[IM_AVERAGE_COMPUTATION_COULD_OVERFLOW]]></configKey> - - <description><![CDATA[<p>The code computes the average of two integers using either division or signed right shift, -and then uses the result as the index of an array. -If the values being averaged are very large, this can overflow (resulting in the computation -of a negative average). Assuming that the result is intended to be nonnegative, you -can use an unsigned right shift instead. In other words, rather that using <code>(low+high)/2</code>, -use <code>(low+high) >>> 1</code> -</p> -<p>This bug exists in many earlier implementations of binary search and merge sort. -Martin Buchholz <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6412541">found and fixed it</a> -in the JDK libraries, and Joshua Bloch -<a href="http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html">widely -publicized the bug pattern</a>. -</p>]]></description> + + </rule> <rule key="IM_BAD_CHECK_FOR_ODD"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Check for oddness that won't work for negative numbers ]]></name> <configKey><![CDATA[IM_BAD_CHECK_FOR_ODD]]></configKey> - - <description><![CDATA[<p> -The code uses x % 2 == 1 to check to see if a value is odd, but this won't work -for negative numbers (e.g., (-5) % 2 == -1). If this code is intending to check -for oddness, consider using x & 1 == 1, or x % 2 != 0. -</p>]]></description> + + </rule> <rule key="DMI_HARDCODED_ABSOLUTE_FILENAME"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Code contains a hard coded reference to an absolute pathname]]></name> <configKey><![CDATA[DMI_HARDCODED_ABSOLUTE_FILENAME]]></configKey> - - <description><![CDATA[<p>This code constructs a File object using a hard coded to an absolute pathname -(e.g., <code>new File("/home/dannyc/workspace/j2ee/src/share/com/sun/enterprise/deployment");</code> -</p>]]></description> + + </rule> <rule key="DMI_BAD_MONTH"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Bad constant value for month]]></name> <configKey><![CDATA[DMI_BAD_MONTH]]></configKey> - - <description><![CDATA[<p> -This code passes a constant month -value outside the expected range of 0..11 to a method. -</p>]]></description> + + </rule> <rule key="DMI_USELESS_SUBSTRING"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Invocation of substring(0), which returns the original value]]></name> <configKey><![CDATA[DMI_USELESS_SUBSTRING]]></configKey> - - <description><![CDATA[<p> -This code invokes substring(0) on a String, which returns the original value. -</p>]]></description> + + </rule> <rule key="DMI_CALLING_NEXT_FROM_HASNEXT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - hasNext method invokes next]]></name> <configKey><![CDATA[DMI_CALLING_NEXT_FROM_HASNEXT]]></configKey> - - <description><![CDATA[<p> -The hasNext() method invokes the next() method. This is almost certainly wrong, -since the hasNext() method is not supposed to change the state of the iterator, -and the next method is supposed to change the state of the iterator. -</p>]]></description> + + </rule> <rule key="SWL_SLEEP_WITH_LOCK_HELD"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Method calls Thread.sleep() with a lock held]]></name> <configKey><![CDATA[SWL_SLEEP_WITH_LOCK_HELD]]></configKey> - - <description><![CDATA[<p> - This method calls Thread.sleep() with a lock held. This may result - in very poor performance and scalability, or a deadlock, since other threads may - be waiting to acquire the lock. It is a much better idea to call - wait() on the lock, which releases the lock and allows other threads - to run. - </p>]]></description> + + </rule> <rule key="DB_DUPLICATE_BRANCHES"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Method uses the same code for two branches]]></name> <configKey><![CDATA[DB_DUPLICATE_BRANCHES]]></configKey> - - <description><![CDATA[<p> - This method uses the same code to implement two branches of a conditional branch. - Check to ensure that this isn't a coding mistake. - </p>]]></description> + + </rule> <rule key="DB_DUPLICATE_SWITCH_CLAUSES"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Method uses the same code for two switch clauses]]></name> <configKey><![CDATA[DB_DUPLICATE_SWITCH_CLAUSES]]></configKey> - - <description><![CDATA[<p> - This method uses the same code to implement two clauses of a switch statement. - This could be a case of duplicate code, but it might also indicate - a coding mistake. - </p>]]></description> + + </rule> <rule key="XFB_XML_FACTORY_BYPASS"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Dodgy - Method directly allocates a specific implementation of xml interfaces]]></name> <configKey><![CDATA[XFB_XML_FACTORY_BYPASS]]></configKey> - - <description><![CDATA[<p> - This method allocates a specific implementation of an xml interface. It is preferable to use - the supplied factory classes to create these objects so that the implementation can be - changed at runtime. See - </p> - <ul> - <li>javax.xml.parsers.DocumentBuilderFactory</li> - <li>javax.xml.parsers.SAXParserFactory</li> - <li>javax.xml.transform.TransformerFactory</li> - <li>org.w3c.dom.Document.create<i>XXXX</i></li> - </ul> - <p>for details.</p>]]></description> + + </rule> <rule key="CI_CONFUSED_INHERITANCE"> -<priority>MINOR</priority> + <priority>MINOR</priority> <name><![CDATA[Dodgy - Class is final but declares protected field]]></name> <configKey><![CDATA[CI_CONFUSED_INHERITANCE]]></configKey> - - <description><![CDATA[<p> - This class is declared to be final, but declares fields to be protected. Since the class - is final, it can not be derived from, and the use of protected is confusing. The access - modifier for the field should be changed to private or public to represent the true - use for the field. - </p>]]></description> + + </rule> <rule key="QBA_QUESTIONABLE_BOOLEAN_ASSIGNMENT"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Method assigns boolean literal in boolean expression]]></name> <configKey><![CDATA[QBA_QUESTIONABLE_BOOLEAN_ASSIGNMENT]]></configKey> - - <description><![CDATA[<p> - This method assigns a literal boolean value (true or false) to a boolean variable inside - an if or while expression. Most probably this was supposed to be a boolean comparison using - ==, not an assignment using =. - </p>]]></description> + + </rule> <rule key="GC_UNCHECKED_TYPE_IN_GENERIC_CALL"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Bad practice - Unchecked type in generic call]]></name> <configKey><![CDATA[GC_UNCHECKED_TYPE_IN_GENERIC_CALL]]></configKey> - - <description><![CDATA[<p> This call to a generic collection method passes an argument - while compile type Object where a specific type from - the generic type parameters is expected. - Thus, neither the standard Java type system nor static analysis - can provide useful information on whether the - object being passed as a parameter is of an appropriate type. - </p>]]></description> + + </rule> <rule key="GC_UNRELATED_TYPES"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - No relationship between generic parameter and method argument]]></name> <configKey><![CDATA[GC_UNRELATED_TYPES]]></configKey> - - <description><![CDATA[<p> This call to a generic collection method contains an argument - with an incompatible class from that of the collection's parameter - (i.e., the type of the argument is neither a supertype nor a subtype - of the corresponding generic type argument). - Therefore, it is unlikely that the collection contains any objects - that are equal to the method argument used here. - Most likely, the wrong value is being passed to the method.</p> - <p>In general, instances of two unrelated classes are not equal. - For example, if the <code>Foo</code> and <code>Bar</code> classes - are not related by subtyping, then an instance of <code>Foo</code> - should not be equal to an instance of <code>Bar</code>. - Among other issues, doing so will likely result in an equals method - that is not symmetrical. For example, if you define the <code>Foo</code> class - so that a <code>Foo</code> can be equal to a <code>String</code>, - your equals method isn't symmetrical since a <code>String</code> can only be equal - to a <code>String</code>. - </p> - <p>In rare cases, people do define nonsymmetrical equals methods and still manage to make - their code work. Although none of the APIs document or guarantee it, it is typically - the case that if you check if a <code>Collection<String></code> contains - a <code>Foo</code>, the equals method of argument (e.g., the equals method of the - <code>Foo</code> class) used to perform the equality checks. - </p>]]></description> + + </rule> <rule key="DMI_COLLECTIONS_SHOULD_NOT_CONTAIN_THEMSELVES"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Collections should not contain themselves]]></name> <configKey><![CDATA[DMI_COLLECTIONS_SHOULD_NOT_CONTAIN_THEMSELVES]]></configKey> - - <description><![CDATA[<p> This call to a generic collection's method would only make sense if a collection contained -itself (e.g., if <code>s.contains(s)</code> were true). This is unlikely to be true and would cause -problems if it were true (such as the computation of the hash code resulting in infinite recursion). -It is likely that the wrong value is being passed as a parameter. - </p>]]></description> + + </rule> <rule key="DMI_VACUOUS_SELF_COLLECTION_CALL"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Vacuous call to collections]]></name> <configKey><![CDATA[DMI_VACUOUS_SELF_COLLECTION_CALL]]></configKey> - - <description><![CDATA[<p> This call doesn't make sense. For any collection <code>c</code>, calling <code>c.containsAll(c)</code> should -always be true, and <code>c.retainAll(c)</code> should have no effect. - </p>]]></description> + + </rule> <rule key="DMI_USING_REMOVEALL_TO_CLEAR_COLLECTION"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Don't use removeAll to clear a collection]]></name> <configKey><![CDATA[DMI_USING_REMOVEALL_TO_CLEAR_COLLECTION]]></configKey> - - <description><![CDATA[<p> If you want to remove all elements from a collection <code>c</code>, use <code>c.clear</code>, -not <code>c.removeAll(c)</code>. - </p>]]></description> + + </rule> <rule key="STCAL_STATIC_CALENDAR_INSTANCE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Static Calendar]]></name> <configKey><![CDATA[STCAL_STATIC_CALENDAR_INSTANCE]]></configKey> - - <description><![CDATA[<p>Even though the JavaDoc does not contain a hint about it, Calendars are inherently unsafe for multihtreaded use. -Sharing a single instance across thread boundaries without proper synchronization will result in erratic behavior of the -application. Under 1.4 problems seem to surface less often than under Java 5 where you will probably see -random ArrayIndexOutOfBoundsExceptions or IndexOutOfBoundsExceptions in sun.util.calendar.BaseCalendar.getCalendarDateFromFixedDate().</p> -<p>You may also experience serialization problems.</p> -<p>Using an instance field is recommended.</p> -<p>For more information on this see <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6231579">Sun Bug #6231579</a> -and <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6178997">Sun Bug #6178997</a>.</p>]]></description> + + </rule> <rule key="STCAL_INVOKE_ON_STATIC_CALENDAR_INSTANCE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Call to static Calendar]]></name> <configKey><![CDATA[STCAL_INVOKE_ON_STATIC_CALENDAR_INSTANCE]]></configKey> - - <description><![CDATA[<p>Even though the JavaDoc does not contain a hint about it, Calendars are inherently unsafe for multihtreaded use. -The detector has found a call to an instance of Calendar that has been obtained via a static -field. This looks suspicous.</p> -<p>For more information on this see <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6231579">Sun Bug #6231579</a> -and <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6178997">Sun Bug #6178997</a>.</p>]]></description> + + </rule> <rule key="STCAL_STATIC_SIMPLE_DATE_FORMAT_INSTANCE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Static DateFormat]]></name> <configKey><![CDATA[STCAL_STATIC_SIMPLE_DATE_FORMAT_INSTANCE]]></configKey> - - <description><![CDATA[<p>As the JavaDoc states, DateFormats are inherently unsafe for multithreaded use. -Sharing a single instance across thread boundaries without proper synchronization will result in erratic behavior of the -application.</p> -<p>You may also experience serialization problems.</p> -<p>Using an instance field is recommended.</p> -<p>For more information on this see <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6231579">Sun Bug #6231579</a> -and <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6178997">Sun Bug #6178997</a>.</p>]]></description> + + </rule> <rule key="STCAL_INVOKE_ON_STATIC_DATE_FORMAT_INSTANCE"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Call to static DateFormat]]></name> <configKey><![CDATA[STCAL_INVOKE_ON_STATIC_DATE_FORMAT_INSTANCE]]></configKey> - - <description><![CDATA[<p>As the JavaDoc states, DateFormats are inherently unsafe for multithreaded use. -The detector has found a call to an instance of DateFormat that has been obtained via a static -field. This looks suspicous.</p> -<p>For more information on this see <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6231579">Sun Bug #6231579</a> -and <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6178997">Sun Bug #6178997</a>.</p>]]></description> + + </rule> <rule key="TQ_ALWAYS_VALUE_USED_WHERE_NEVER_REQUIRED"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name> <![CDATA[Correctness - Value annotated as carrying a type qualifier used where a value that must not carry that qualifier is required]]></name> <configKey><![CDATA[TQ_ALWAYS_VALUE_USED_WHERE_NEVER_REQUIRED]]></configKey> - - <description><![CDATA[<p> - A value specified as carrying a type qualifier annotation is - consumed in a location or locations requiring that the value not - carry that annotation. - </p> - - <p> - More precisely, a value annotated with a type qualifier specifying when=ALWAYS - is guaranteed to reach a use or uses where the same type qualifier specifies when=NEVER. - </p> - - <p> - For example, say that @NonNegative is a nickname for - the type qualifier annotation @Negative(when=When.NEVER). - The following code will generate this warning because - the return statement requires a @NonNegative value, - but receives one that is marked as @Negative. - </p> - <blockquote> -<pre> -public @NonNegative Integer example(@Negative Integer value) { - return value; -} -</pre> - </blockquote>]]></description> + + </rule> <rule key="TQ_NEVER_VALUE_USED_WHERE_ALWAYS_REQUIRED"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name> <![CDATA[Correctness - Value annotated as never carrying a type qualifier used where value carrying that qualifier is required]]></name> <configKey><![CDATA[TQ_NEVER_VALUE_USED_WHERE_ALWAYS_REQUIRED]]></configKey> - - <description><![CDATA[<p> - A value specified as not carrying a type qualifier annotation is guaranteed - to be consumed in a location or locations requiring that the value does - carry that annotation. - </p> - - <p> - More precisely, a value annotated with a type qualifier specifying when=NEVER - is guaranteed to reach a use or uses where the same type qualifier specifies when=ALWAYS. - </p> - - <p> - TODO: example - </p>]]></description> + + </rule> <rule key="TQ_MAYBE_SOURCE_VALUE_REACHES_ALWAYS_SINK"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name> <![CDATA[Correctness - Value that might not carry a type qualifier is always used in a way requires that type qualifier]]></name> <configKey><![CDATA[TQ_MAYBE_SOURCE_VALUE_REACHES_ALWAYS_SINK]]></configKey> - - <description><![CDATA[<p> - A value that is annotated as possibility not being an instance of - the values denoted by the type qualifier, and the value is guaranteed to be used - in a way that requires values denoted by that type qualifier. - </p>]]></description> + + </rule> <rule key="TQ_MAYBE_SOURCE_VALUE_REACHES_NEVER_SINK"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name> <![CDATA[Correctness - Value that might carry a type qualifier is always used in a way prohibits it from having that type qualifier]]></name> <configKey><![CDATA[TQ_MAYBE_SOURCE_VALUE_REACHES_NEVER_SINK]]></configKey> - - <description><![CDATA[<p> - A value that is annotated as possibility being an instance of - the values denoted by the type qualifier, and the value is guaranteed to be used - in a way that prohibits values denoted by that type qualifier. - </p>]]></description> + + </rule> <rule key="TQ_EXPLICIT_UNKNOWN_SOURCE_VALUE_REACHES_NEVER_SINK"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Explicit annotation inconsistent with use]]></name> <configKey><![CDATA[TQ_EXPLICIT_UNKNOWN_SOURCE_VALUE_REACHES_NEVER_SINK]]></configKey> - - <description><![CDATA[<p> - A value is used in a way that requires it to be never be a value denoted by a type qualifier, but - there is an explicit annotation stating that it is not known where the value is prohibited from having that type qualifier. - Either the usage or the annotation is incorrect. - </p>]]></description> + + </rule> <rule key="TQ_EXPLICIT_UNKNOWN_SOURCE_VALUE_REACHES_ALWAYS_SINK"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Explicit annotation inconsistent with use]]></name> <configKey><![CDATA[TQ_EXPLICIT_UNKNOWN_SOURCE_VALUE_REACHES_ALWAYS_SINK]]></configKey> - - <description><![CDATA[<p> - A value is used in a way that requires it to be always be a value denoted by a type qualifier, but - there is an explicit annotation stating that it is not known where the value is required to have that type qualifier. - Either the usage or the annotation is incorrect. - </p>]]></description> + + </rule> <rule key="IO_APPENDING_TO_OBJECT_OUTPUT_STREAM"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Correctness - Doomed attempt to append to an object output stream]]></name> <configKey><![CDATA[IO_APPENDING_TO_OBJECT_OUTPUT_STREAM]]></configKey> - - <description><![CDATA[<p> - This code opens a file in append mode and then wraps the result in an object output stream. - This won't allow you to append to an existing object output stream stored in a file. If you want to be - able to append to an object output stream, you need to keep the object output stream open. - </p> - <p>The only situation in which opening a file in append mode and the writing an object output stream - could work is if on reading the file you plan to open it in random access mode and seek to the byte offset - where the append started. - </p> - - <p> - TODO: example. - </p>]]></description> + + </rule> <rule key="WL_USING_GETCLASS_RATHER_THAN_CLASS_LITERAL"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name><![CDATA[Multithreaded correctness - Sychronization on getClass rather than class literal]]></name> <configKey><![CDATA[WL_USING_GETCLASS_RATHER_THAN_CLASS_LITERAL]]></configKey> - - <description><![CDATA[<p> - This instance method synchronizes on <code>this.getClass()</code>. If this class is subclassed, - subclasses will synchronize on the class object for the subclass, which isn't likely what was intended. - For example, consider this code from java.awt.Label: - <pre> - private static final String base = "label"; - private static int nameCounter = 0; - String constructComponentName() { - synchronized (getClass()) { - return base + nameCounter++; - } - } - </pre></p> - <p>Subclasses of <code>Label</code> won't synchronize on the same subclass, giving rise to a datarace. - Instead, this code should be synchronizing on <code>Label.class</code> - <pre> - private static final String base = "label"; - private static int nameCounter = 0; - String constructComponentName() { - synchronized (Label.class) { - return base + nameCounter++; - } - } - </pre></p> - <p>Bug pattern contributed by Jason Mehrens</p>]]></description> + + </rule> <rule key="SF_SWITCH_FALLTHROUGH"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name> <![CDATA[Switch statement found where one case falls through to the next case]]></name> <configKey><![CDATA[SF_SWITCH_FALLTHROUGH]]></configKey> - - <description><![CDATA[<p> - This method contains a switch statement where one case branch will fall - through to the next case. Usually you need to end this case with a break or return. - </p>]]></description> - </rule> + + + </rule> <rule key="SF_SWITCH_NO_DEFAULT"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name> <![CDATA[Switch statement found where default case is missing]]></name> <configKey><![CDATA[SF_SWITCH_NO_DEFAULT]]></configKey> - - <description><![CDATA[<p> - This method contains a switch statement where default case is missing. - Usually you need to provide a default case. - </p>]]></description> - </rule> + + + </rule> <rule key="SF_DEAD_STORE_DUE_TO_SWITCH_FALLTHROUGH"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name> <![CDATA[Dead store due to switch statement fall through]]></name> <configKey><![CDATA[SF_DEAD_STORE_DUE_TO_SWITCH_FALLTHROUGH]]></configKey> - - <description><![CDATA[<p> - A value stored in the previous switch case is overwritten here due - to a switch fall through. It is likely that you forgot to put a - break or return at the end of the previous case. - </p>]]></description> + + </rule> <rule key="SF_DEAD_STORE_DUE_TO_SWITCH_FALLTHROUGH_TO_THROW"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name> <![CDATA[Dead store due to switch statement fall through to throw]]></name> <configKey><![CDATA[SF_DEAD_STORE_DUE_TO_SWITCH_FALLTHROUGH_TO_THROW]]></configKey> - - <description><![CDATA[<p> - A value stored in the previous switch case is ignored here due to a switch fall through to a place where an exception is thrown. - It is likely that you forgot to put a break or return at the end of the previous case. - </p>]]></description> + + </rule> <rule key="NM_CLASS_NAMING_CONVENTION"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name> <![CDATA[Class names should start with an upper case letter]]></name> <configKey><![CDATA[NM_CLASS_NAMING_CONVENTION]]></configKey> - - <description><![CDATA[<p> - Class names should be nouns, in mixed case with the first letter of each internal word capitalized. - Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations - (unless the abbreviation is much more widely used than the long form, such as URL or HTML). - </p>]]></description> - </rule> + + + </rule> <rule key="NM_FIELD_NAMING_CONVENTION"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name> <![CDATA[Field names should start with a lower case letter]]></name> <configKey><![CDATA[NM_FIELD_NAMING_CONVENTION]]></configKey> - - <description><![CDATA[<p> - Names of fields that are not final should be in mixed case - with a lowercase first letter and the first letters of subsequent words capitalized. - </p>]]></description> - </rule> + + + </rule> <rule key="NM_METHOD_NAMING_CONVENTION"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name> <![CDATA[Method names should start with a lower case letter]]></name> <configKey><![CDATA[NM_METHOD_NAMING_CONVENTION]]></configKey> - - <description><![CDATA[<p> - Methods should be verbs, in mixed case with the first letter lowercase, - with the first letter of each internal word capitalized. - </p>]]></description> - </rule> + + + </rule> <rule key="SE_BAD_FIELD"> -<priority>MAJOR</priority> + <priority>MAJOR</priority> <name> <![CDATA[Non-transient non-serializable instance field in serializable class]]></name> <configKey><![CDATA[SE_BAD_FIELD]]></configKey> - - <description><![CDATA[<p> - This Serializable class defines a non-primitive instance field which is neither transient, - Serializable, or <code>java.lang.Object</code>, and does not appear to implement the <code>Externalizable</code> - interface or the <code>readObject()</code> and <code>writeObject()</code> methods. - Objects of this class will not be deserialized correctly if a non-Serializable object is stored in this field. - </p>]]></description> - </rule> + + + </rule> <rule key="NM_BAD_EQUAL"> -<priority>CRITICAL</priority> + <priority>CRITICAL</priority> <name> <![CDATA[Class defines equal(Object); should it be equals(Object)?]]></name> <configKey><![CDATA[NM_BAD_EQUAL]]></configKey> - - <description><![CDATA[<p> - This class defines a method <code>equal(Object)</code>. - This method does not override the <code>equals(Object)</code> method - in <code>java.lang.Object</code>, which is probably what was intended. - </p>]]></description> - </rule> - <rule key="NM_LCASE_HASHCODE"> -<priority>CRITICAL</priority> + + + </rule> + <rule key="NM_LCASE_HASHCODE"> + <priority>CRITICAL</priority> <name> <![CDATA[Class defines hashcode(); should it be hashCode()?]]></name> <configKey><![CDATA[NM_LCASE_HASHCODE]]></configKey> - - <description><![CDATA[<p> - This class defines a method called <code>hashcode()</code>. - This method does not override the <code>hashCode()</code> - method in <code>java.lang.Object</code>, which is probably what was intended. - </p>]]></description> - </rule> - <rule key="NM_LCASE_TOSTRING"> -<priority>MAJOR</priority> + + + </rule> + <rule key="NM_LCASE_TOSTRING"> + <priority>MAJOR</priority> <name> <![CDATA[Class defines tostring(); should it be toString()?]]></name> <configKey><![CDATA[NM_LCASE_TOSTRING]]></configKey> - - <description><![CDATA[<p> - This class defines a method called <code>tostring()</code>. - This method does not override the <code>toString()</code> - method in <code>java.lang.Object</code>, which is probably what was intended. - </p>]]></description> - </rule> - <rule key="NM_LCASE_TOSTRING"> -<priority>MAJOR</priority> + + + </rule> + <rule key="NM_LCASE_TOSTRING"> + <priority>MAJOR</priority> <name> <![CDATA[Class defines tostring(); should it be toString()?]]></name> <configKey><![CDATA[NM_LCASE_TOSTRING]]></configKey> - - <description><![CDATA[<p> - This class defines a method called <code>tostring()</code>. - This method does not override the <code>toString()</code> - method in <code>java.lang.Object</code>, which is probably what was intended. - </p>]]></description> + + </rule> <rule key="BAC_BAD_APPLET_CONSTRUCTOR"> -<priority>INFO</priority> + <priority>INFO</priority> <name><![CDATA[Experimental - Bad Applet Constructor relies on uninitialized AppletStub]]></name> <configKey><![CDATA[BAC_BAD_APPLET_CONSTRUCTOR]]></configKey> - <description><![CDATA[<p> - This constructor calls methods in the parent Applet that rely on the AppletStub. Since the AppletStub - isn't initialized until the init() method of this applet is called, these methods will not perform - correctly. - </p>]]></description> + </rule> <rule key="UOE_USE_OBJECT_EQUALS"> -<priority>INFO</priority> + <priority>INFO</priority> <name><![CDATA[Experimental - Calls to equals on a final class that doesn't override Object's equals method]]></name> <configKey><![CDATA[UOE_USE_OBJECT_EQUALS]]></configKey> - <description><![CDATA[<p> - This method invokes the .equals(Object o) method on a final class that doesn't override the equals method - in the Object class, effectively making the equals method test for sameness, like ==. It is good to use - the .equals method, but you should consider adding an .equals method in this class. - </p> - <p>[Bill Pugh]: Sorry, but I strongly disagree that this should be a warning, and I think your code - is just fine. Users of your code shouldn't care how you've implemented equals(), and they should never - depend on == to compare instances, since that bypasses the libraries ability to control how objects - are compared. - </p>]]></description> + </rule> <rule key="CD_CIRCULAR_DEPENDENCY"> -<priority>INFO</priority> + <priority>INFO</priority> <name><![CDATA[Experimental - Test for circular dependencies among classes]]></name> <configKey><![CDATA[CD_CIRCULAR_DEPENDENCY]]></configKey> - <description><![CDATA[<p> - This class has a circular dependency with other classes. This makes building these classes - difficult, as each is dependent on the other to build correctly. Consider using interfaces - to break the hard dependency. - </p>]]></description> + </rule> <rule key="IMA_INEFFICIENT_MEMBER_ACCESS"> -<priority>INFO</priority> + <priority>INFO</priority> <name><![CDATA[Experimental - Method accesses a private member variable of owning class]]></name> <configKey><![CDATA[IMA_INEFFICIENT_MEMBER_ACCESS]]></configKey> - <description><![CDATA[<p> - This method of an inner class reads from or writes to a private member variable of the owning class, - or calls a private method of the owning class. The compiler must generate a special method to access this - private member, causing this to be less efficient. Relaxing the protection of the member variable or method - will allow the compiler to treat this as a normal access. - </p>]]></description> + </rule> <rule key="USM_USELESS_SUBCLASS_METHOD"> -<priority>INFO</priority> + <priority>INFO</priority> <name><![CDATA[Experimental - Method superfluously delegates to parent class method]]></name> <configKey><![CDATA[USM_USELESS_SUBCLASS_METHOD]]></configKey> - <description><![CDATA[<p> - This derived method merely calls the same superclass method passing in the exact parameters - received. This method can be removed, as it provides no additional value. - </p>]]></description> + </rule> <rule key="USM_USELESS_ABSTRACT_METHOD"> -<priority>INFO</priority> + <priority>INFO</priority> <name><![CDATA[Experimental - Abstract Method is already defined in implemented interface]]></name> <configKey><![CDATA[USM_USELESS_ABSTRACT_METHOD]]></configKey> - <description><![CDATA[<p> - This abstract method is already defined in an interface that is implemented by this abstract - class. This method can be removed, as it provides no additional value. - </p>]]></description> + </rule> <rule key="OBL_UNSATISFIED_OBLIGATION"> -<priority>INFO</priority> + <priority>INFO</priority> <name><![CDATA[Experimental - Method may fail to clean up stream or resource]]></name> <configKey><![CDATA[OBL_UNSATISFIED_OBLIGATION]]></configKey> - <description><![CDATA[<p> - This method may fail to clean up (close, dispose of) a stream, - database object, or other - resource requiring an explicit cleanup operation. - </p> - <p> - In general, if a method opens a stream or other resource, - the method should use a try/finally block to ensure that - the stream or resource is cleaned up before the method - returns. - </p> - <p> - This bug pattern is essentially the same as the - OS_OPEN_STREAM and ODR_OPEN_DATABASE_RESOURCE - bug patterns, but is based on a different - (and hopefully better) static analysis technique. - We are interested is getting feedback about the - usefulness of this bug pattern. - To send feedback, either: - </p> - <ul> - <li>send email to findbugs@cs.umd.edu</li> - <li>file a bug report: <a href="http://findbugs.sourceforge.net/reportingBugs.html">http://findbugs.sourceforge.net/reportingBugs.html</a></li> - </ul> - <p> - In particular, - the false-positive suppression heuristics for this - bug pattern have not been extensively tuned, so - reports about false positives are helpful to us. - </p> - <p> - See Weimer and Necula, <i>Finding and Preventing Run-Time Error Handling Mistakes</i>, for - a description of the analysis technique. - </p>]]></description> + </rule> <rule key="FB_UNEXPECTED_WARNING"> -<priority>INFO</priority> + <priority>INFO</priority> <name><![CDATA[Experimental - Unexpected/undesired warning from FindBugs]]></name> <configKey><![CDATA[FB_UNEXPECTED_WARNING]]></configKey> - <description><![CDATA[<p> - FindBugs generated a warning that, according to a @NoWarning annotated, - is unexpected or undesired - </p>]]></description> + </rule> <rule key="FB_MISSING_EXPECTED_WARNING"> -<priority>INFO</priority> + <priority>INFO</priority> <name><![CDATA[Experimental - Missing expected or desired warning from FindBugs]]></name> <configKey><![CDATA[FB_MISSING_EXPECTED_WARNING]]></configKey> - <description><![CDATA[<p> - FindBugs didn't generate generated a warning that, according to a @ExpectedWarning annotated, - is expected or desired - </p>]]></description> + </rule> <rule key="LG_LOST_LOGGER_DUE_TO_WEAK_REFERENCE"> -<priority>INFO</priority> + <priority>INFO</priority> <name><![CDATA[Experimental - Potential lost logger changes due to weak reference in OpenJDK]]></name> <configKey><![CDATA[LG_LOST_LOGGER_DUE_TO_WEAK_REFERENCE]]></configKey> - <description><![CDATA[<p> - OpenJDK introduces a potential incompatibility. - In particular, the java.util.logging.Logger behavior has - changed. Instead of using strong references, it now uses weak references - internally. That's a reasonable change, but unfortunately some code relies on - the old behavior - when changing logger configuration, it simply drops the - logger reference. That means that the garbage collector is free to reclaim - that memory, which means that the logger configuration is lost. For example, - consider: - </p> - <p><pre>public static void initLogging() throws Exception { - Logger logger = Logger.getLogger("edu.umd.cs"); - logger.addHandler(new FileHandler()); // call to change logger configuration - logger.setUseParentHandlers(false); // another call to change logger configuration - }</pre></p> - <p>The logger reference is lost at the end of the method (it doesn't - escape the method), so if you have a garbage collection cycle just - after the call to initLogging, the logger configuration is lost - (because Logger only keeps weak references).</p> - <p><pre>public static void main(String[] args) throws Exception { - initLogging(); // adds a file handler to the logger - System.gc(); // logger configuration lost - Logger.getLogger("edu.umd.cs").info("Some message"); // this isn't logged to the file as expected - }</pre></p> - <p><em>Ulf Ochsenfahrt and Eric Fellheimer</em> - </p>]]></description> + </rule> </rules> diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsRuleRepositoryTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsRuleRepositoryTest.java index 1a5059f2bd5..bfdae0e50f7 100644 --- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsRuleRepositoryTest.java +++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsRuleRepositoryTest.java @@ -41,7 +41,6 @@ public class FindbugsRuleRepositoryTest { assertThat(rules.size(), greaterThan(300)); for (Rule rule : rules) { assertNotNull(rule.getKey()); - assertNotNull(rule.getDescription()); assertNotNull(rule.getConfigKey()); assertNotNull(rule.getName()); } diff --git a/plugins/sonar-pmd-plugin/src/main/resources/org/sonar/plugins/pmd/rules.xml b/plugins/sonar-pmd-plugin/src/main/resources/org/sonar/plugins/pmd/rules.xml index b67167d0e91..7807310d803 100644 --- a/plugins/sonar-pmd-plugin/src/main/resources/org/sonar/plugins/pmd/rules.xml +++ b/plugins/sonar-pmd-plugin/src/main/resources/org/sonar/plugins/pmd/rules.xml @@ -1,2399 +1,1788 @@ <rules> <!-- PMD 4.2.5 --> - <rule key="AvoidThrowingNewInstanceOfSameException" > -<priority>MAJOR</priority> - <name><![CDATA[Strict Exception - Avoid throwing new instance of same exception]]></name> + <rule key="AvoidThrowingNewInstanceOfSameException"> + <priority>MAJOR</priority> + <configKey>rulesets/strictexception.xml/AvoidThrowingNewInstanceOfSameException</configKey> - - <description> - <![CDATA[Catch blocks that merely rethrow a caught exception wrapped inside a new instance of the same type only add to code size and runtime complexity. Example : -<pre> -public class Foo { - void bar() { - try { - // do something - } catch (SomeException se) { - // harmless comment - throw new SomeException(se); - } - } -} -</pre>]]></description> - </rule> - - <rule key="CallSuperFirst" > -<priority>MAJOR</priority> - <name><![CDATA[Android - call super first]]></name> + + + </rule> + + <rule key="CallSuperFirst"> + <priority>MAJOR</priority> + <configKey>rulesets/android.xml/CallSuperFirst</configKey> - - <description> - <![CDATA[Super should be called at the start of the method. Example : -<pre> -public class DummyActivity extends Activity { - public void onCreate(Bundle bundle) { - // missing call to super.onCreate(bundle) - foo(); - } -} -</pre>]]></description> - </rule> - - <rule key="CallSuperLast" > -<priority>MAJOR</priority> - <name><![CDATA[Android - call super last]]></name> + + + </rule> + + <rule key="CallSuperLast"> + <priority>MAJOR</priority> + <configKey>rulesets/android.xml/CallSuperLast</configKey> - <description> - <![CDATA[Super should be called at the end of the method. Example : -<pre> -public class DummyActivity extends Activity { - public void onPause() { - foo(); - // missing call to super.onPause() - } -} -</pre>]]></description> - </rule> - - <rule key="ProtectLogD" > -<priority>MAJOR</priority> - <name><![CDATA[Android - Protect LOGD]]></name> - <configKey>rulesets/android.xml/ProtectLogD</configKey> - <description> - <![CDATA[Log.d calls should be protected by checking Config.LOGD first. Example : -<pre> -public class DummyActivity extends Activity { - public void foo() { - Log.d("TAG", "msg1"); // Bad + </rule> + + <rule key="ProtectLogD"> + <priority>MAJOR</priority> + + <configKey>rulesets/android.xml/ProtectLogD</configKey> - bar(); - if (Config.LOGD) Log.d("TAG", "msg1"); // Good - } -} -</pre>]]></description> </rule> - <rule key="ProtectLogV" > -<priority>MAJOR</priority> - <name><![CDATA[Android - Protect LOGV]]></name> + <rule key="ProtectLogV"> + <priority>MAJOR</priority> + <configKey>rulesets/android.xml/ProtectLogV</configKey> - - <description> - <![CDATA[Log.v calls should be protected by checking Config.LOGV first. Example : -<pre> -public class DummyActivity extends Activity { - public void foo() { - Log.v("TAG", "msg1"); // Bad - bar(); - if (Config.LOGV) Log.v("TAG", "msg1"); // Good - } -} -</pre>]]></description> - </rule> - - <!-- PMD 4.2.3 --> - <rule key="EmptyInitializer" > -<priority>MAJOR</priority> - <name><![CDATA[Basic - Empty Initializer]]></name> - <configKey>rulesets/basic.xml/EmptyInitializer</configKey> - - <description> - <![CDATA[An empty initializer was found. Example : -<pre> -public class Foo { + </rule> - static {} // Why ? - {} // Again, why ? + <!-- PMD 4.2.3 --> + <rule key="EmptyInitializer"> + <priority>MAJOR</priority> -} -</pre>]]></description> - </rule> + <configKey>rulesets/basic.xml/EmptyInitializer</configKey> + </rule> <!-- PMD 4.2.2 --> - <rule key="CyclomaticComplexity" > -<priority>MAJOR</priority> - <name><![CDATA[Code size - cyclomatic complexity]]></name> + <rule key="CyclomaticComplexity"> + <priority>MAJOR</priority> + <configKey>rulesets/codesize.xml/CyclomaticComplexity</configKey> - - <description> - <![CDATA[Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.]]></description> + + <param key="reportLevel" type="i"> - <description><![CDATA[The Cyclomatic Complexity reporting threshold. Default is 10.]]></description> + </param> <param key="showClassesComplexity" type="b"> - <description> - <![CDATA[Indicate if class average violation should be added to the report. Default is true.]]></description> + </param> <param key="showMethodsComplexity" type="b"> - <description> - <![CDATA[Indicate if method average violation should be added to the report. Default is true.]]></description> + </param> </rule> - <rule key="AvoidStringBufferField" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid StringBuffer field]]></name> + <rule key="AvoidStringBufferField"> + <priority>MAJOR</priority> + <configKey>rulesets/strings.xml/AvoidStringBufferField</configKey> - - <description> - <![CDATA[StringBuffers can grow quite a lot, and so may become a source of memory leak (if the owning class has a long life time). Example : -<pre> -class Foo { - private StringBuffer memoryLeak; -} -</pre>]]></description> - </rule> - - <rule key="DoNotThrowExceptionInFinally" > -<priority>MAJOR</priority> - <name><![CDATA[Strict Exception - Do not throw exception in finally]]></name> + + + </rule> + + <rule key="DoNotThrowExceptionInFinally"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/strictexception.xml/DoNotThrowExceptionInFinally]]></configKey> - - <description><![CDATA[Throwing exception in a finally block is confusing. It may mask exception or a defect of the code, it also render code cleanup uninstable. Example : -<pre> -public class Foo -{ - public void bar() - { - try { - // Here do some stuff - } - catch( Exception e) { - // Handling the issue - } - finally - { - // is this really a good idea ? - throw new Exception(); - } - } -} -</pre> -]]></description> - </rule> - - <rule key="TooManyMethods" > -<priority>MAJOR</priority> - <name><![CDATA[Too many methods]]></name> + + + </rule> + + <rule key="TooManyMethods"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/codesize.xml/TooManyMethods]]></configKey> - - <description> - <![CDATA[A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.]]></description> + + <param key="maxmethods" type="i"> - <description><![CDATA[The method count reporting threshold. Default is 10.]]></description> + </param> </rule> - <rule key="ReturnEmptyArrayRatherThanNull" > -<priority>MINOR</priority> - <name><![CDATA[Return empty array rather than null]]></name> + <rule key="ReturnEmptyArrayRatherThanNull"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/design.xml/ReturnEmptyArrayRatherThanNull]]></configKey> - - <description><![CDATA[For any method that returns an array, it's a better behavior to return an empty array rather than a null reference. Example : -<pre> -public class Example -{ - // Not a good idea... - public int []badBehavior() - { - // ... - return null; - } - - // Good behavior - public String[] bonnePratique() - { - //... - return new String[0]; - } -} -</pre> -]]></description> - </rule> - - <rule key="TooFewBranchesForASwitchStatement" > -<priority>MINOR</priority> - <name><![CDATA[Too few branches for a switch statement]]></name> + + + </rule> + + <rule key="TooFewBranchesForASwitchStatement"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/design.xml/TooFewBranchesForASwitchStatement]]></configKey> - - <description><![CDATA[Swith are designed complex branches, and allow branches to share treatement. Using a switch for only a few branches is ill advised, as switches are not as easy to understand as if. In this case, it's most likely is a good idea to use a if statement instead, at least to increase code readability. Example : -<pre> -// With a minimumNumberCaseForASwitch of 3 -public class Foo { - public void bar() { - switch (condition) { - case ONE: - instruction; - break; - default: - break; // not enough for a 'switch' stmt, - // a simple 'if' stmt would have been more appropriate - } - } -} -</pre> -]]></description> + + <param key="minimumNumberCaseForASwitch" type="i"> - <description><![CDATA[Minimum number of branches for a switch. Default is 3.]]></description> + </param> </rule> - <rule key="AbstractClassWithoutAnyMethod" > -<priority>MAJOR</priority> - <name><![CDATA[Abstract class without any methods]]></name> + <rule key="AbstractClassWithoutAnyMethod"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/AbstractClassWithoutAnyMethod]]></configKey> - - <description><![CDATA[If the abstract class does not provides any methods, it may be just a data container that is not to be instantiated. In this case, it's probably better to use a private or a protected constructor in order to prevent instantiation than make the class misleadingly abstract. Example : -<pre> -public class abstract Example { - String field; - int otherField; -} -</pre> -]]></description> + </rule> - <rule key="DoNotCallGarbageCollectionExplicitly" > -<priority>CRITICAL</priority> - <name><![CDATA[Do not call garbage collection explicitly]]></name> + <rule key="DoNotCallGarbageCollectionExplicitly"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/controversial.xml/DoNotCallGarbageCollectionExplicitly]]></configKey> - - <description> - <![CDATA[Calls to System.gc(), Runtime.getRuntime().gc(), and System.runFinalization() are not advised. Code should have the same behavior whether the garbage collection is disabled using the option -Xdisableexplicitgc or not. Moreover, "modern" jvms do a very good job handling garbage collections. If memory usage issues unrelated to memory leaks develop within an application, it should be dealt with JVM options rather than within the code itself. Example : -<pre> - public class GCCall -{ - public GCCall() - { - // Explicit gc call ! - System.gc(); - } - public void doSomething() - { - // Explicit gc call ! - Runtime.getRuntime().gc(); - } - - public explicitGCcall() { // Explicit gc call ! System.gc(); } - - public void doSomething() { // Explicit gc call ! Runtime.getRuntime().gc(); } -} -</pre>]]></description> - </rule> - - <rule key="AvoidMultipleUnaryOperators" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Multiple Unary Operators]]></name> + + + </rule> + + <rule key="AvoidMultipleUnaryOperators"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic.xml/AvoidMultipleUnaryOperators]]></configKey> - - <description> - <![CDATA[Using multiple unary operators may be a bug, and/or is confusing. Check the usage is not a bug, or consider simplifying the expression. Example : -<pre> -// These are typo bugs, or at best needlessly complex and confusing: -int i = - -1; -int j = + - +1; -int z = ~~2; -boolean b = !!true; -boolean c = !!!true; - -// These are better: -int i = 1; -int j = -1; -int z = 2; -boolean b = true; -boolean c = false; - -// And these just make your brain hurt: -int i = ~-2; -int j = -~7; -</pre> ]]></description> - </rule> - - - <rule key="DoubleCheckedLocking" > -<priority>MAJOR</priority> - <name><![CDATA[Double checked locking]]></name> + + + </rule> + + + <rule key="DoubleCheckedLocking"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic.xml/DoubleCheckedLocking]]></configKey> - - <description> - <![CDATA[Partially created objects can be returned by the Double Checked Locking pattern when used in Java. An optimizing JRE may assign a reference to the baz variable before it creates the object the reference is intended to point to. <a href="http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html">More details</a>. Example : -<pre> -public class Foo { - Object baz; - Object bar() { - if(baz == null) { //baz may be non-null yet not fully created - synchronized(this){ - if(baz == null){ - baz = new Object(); - } - } - } - return baz; - } -} -</pre> ]]></description> - </rule> - - <rule key="NPathComplexity" > -<priority>MAJOR</priority> - <name><![CDATA[NPath complexity]]></name> + + + </rule> + + <rule key="NPathComplexity"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/codesize.xml/NPathComplexity]]></configKey> - - <description> - <![CDATA[The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity. Example : -<pre> -public class Foo { - void bar() { - // lots of complicated code - } - } -</pre> ]]></description> + + <param key="minimum" type="i"> - <description><![CDATA[The npath reporting threshold. Default is 200.]]></description> + </param> </rule> - <rule key="SimplifyBooleanReturns" > -<priority>MINOR</priority> - <name><![CDATA[Simplify boolean returns]]></name> + <rule key="SimplifyBooleanReturns"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/design.xml/SimplifyBooleanReturns]]></configKey> - - <description> - <![CDATA[Avoid unnecessary if..then..else statements when returning a boolean. Example : -<pre> -public class Foo { - private int bar =2; - public boolean isBarEqualsTo(int x) { - // this bit of code - if (bar == x) { - return true; - } else { - return false; - } - // can be replaced with a simple - // return bar == x; - } -} -</pre> - ]]></description> - </rule> - - <rule key="SimplifyBooleanExpressions" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid unnecessary comparisons in boolean expressions]]></name> + + + </rule> + + <rule key="SimplifyBooleanExpressions"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/SimplifyBooleanExpressions]]></configKey> - - <description> - <![CDATA[Avoid unnecessary comparisons in boolean expressions - this complicates simple code. Example : -<pre> -public class Bar { - // can be simplified to - // bar = isFoo(); - private boolean bar = (isFoo() == true); - - public isFoo() { return false;} -} -</pre> - ]]></description> - </rule> - - <rule key="SwitchStmtsShouldHaveDefault" > -<priority>MAJOR</priority> - <name><![CDATA[Switch statements should have default]]></name> + + + </rule> + + <rule key="SwitchStmtsShouldHaveDefault"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/SwitchStmtsShouldHaveDefault]]></configKey> - - <description> - <![CDATA[Switch statements should have a default label. Example : -<pre> -public class Foo { - public void bar() { - int x = 2; - switch (x) { - case 2: int j = 8; - } - } -} -</pre> - ]]></description> - </rule> - - <rule key="DefaultLabelNotLastInSwitchStmt" > -<priority>MAJOR</priority> - <name><![CDATA[Default label not last in switch statement]]></name> + + + </rule> + + <rule key="DefaultLabelNotLastInSwitchStmt"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/DefaultLabelNotLastInSwitchStmt]]></configKey> - - <description> - <![CDATA[Switch statements should have a default label. Example : - <pre> -public class Foo { - void bar(int a) { - switch (a) { - case 1: // do something - break; - default: // the default case should be last, by convention - break; - case 2: - break; - } - } -} - </pre>]]></description> - </rule> - - - <rule key="ClassWithOnlyPrivateConstructorsShouldBeFinal" > -<priority>MAJOR</priority> - <name><![CDATA[Class with only private constructors should be final]]></name> + + + </rule> + + + <rule key="ClassWithOnlyPrivateConstructorsShouldBeFinal"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/ClassWithOnlyPrivateConstructorsShouldBeFinal]]></configKey> - - <description> - <![CDATA[A class with only private constructors should be final, unless the private constructor is called by a inner class. Example : - <pre> -public class Foo { //Should be final - private Foo() { } -} - </pre>]]></description> - </rule> - - <rule key="AvoidFinalLocalVariable" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Final Local Variable]]></name> + + + </rule> + + <rule key="AvoidFinalLocalVariable"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/controversial.xml/AvoidFinalLocalVariable]]></configKey> - - <description> - <![CDATA[Avoid using final local variables, turn them into fields. Example : -<pre> -public class MyClass { - public void foo() { - final String finalLocalVariable; - } -} - </pre>]]></description> - </rule> - - <rule key="UnnecessaryParentheses" > -<priority>MINOR</priority> - <name><![CDATA[Unnecessary parentheses]]></name> + + + </rule> + + <rule key="UnnecessaryParentheses"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/controversial.xml/UnnecessaryParentheses]]></configKey> - - <description> - <![CDATA[Sometimes expressions are wrapped in unnecessary parentheses, making them look like a function call. Example : -<pre> -public class Foo { - boolean bar() { - return (true); - } -} - </pre>]]></description> - </rule> - - <rule key="OverrideBothEqualsAndHashcode" > -<priority>CRITICAL</priority> - <name><![CDATA[Override both equals and hashcode]]></name> + + + </rule> + + <rule key="OverrideBothEqualsAndHashcode"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/basic.xml/OverrideBothEqualsAndHashcode]]></configKey> - - <description> - <![CDATA[Override both public boolean Object.equals(Object other), and public int Object.hashCode(), or override neither. Even if you are inheriting a hashCode() from a parent class, consider implementing hashCode and explicitly delegating to your superclass. Example : -<pre> -// this is bad -public class Bar { - public boolean equals(Object o) { - // do some comparison - } -} - -// and so is this -public class Baz { - public int hashCode() { - // return some hash value - } -} - -// this is OK -public class Foo { - public boolean equals(Object other) { - // do some comparison - } - public int hashCode() { - // return some hash value - } -} -</pre>]]></description> - </rule> - - - <rule key="UnusedImports" > -<priority>INFO</priority> - <name><![CDATA[Unused imports]]></name> + + + </rule> + + + <rule key="UnusedImports"> + <priority>INFO</priority> + <configKey><![CDATA[rulesets/imports.xml/UnusedImports]]></configKey> - - <description> - <![CDATA[Avoid unused import statements. Example : - <pre> -// this is bad -import java.io.File; -public class Foo {} - </pre>]]></description> - </rule> - - <rule key="LocalVariableCouldBeFinal" > -<priority>MINOR</priority> - <name><![CDATA[Local variable could be final]]></name> + + + </rule> + + <rule key="LocalVariableCouldBeFinal"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/optimizations.xml/LocalVariableCouldBeFinal]]></configKey> - - <description> - <![CDATA[A local variable assigned only once can be declared final. Example : - <pre> -public class Bar { - public void foo () { - String a = "a"; //if a will not be assigned again it is better to do this: - final String b = "b"; - } -} - </pre>]]></description> - </rule> - - - <rule key="AbstractNaming" > -<priority>MAJOR</priority> - <name><![CDATA[Abstract naming]]></name> + + + </rule> + + + <rule key="AbstractNaming"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/naming.xml/AbstractNaming]]></configKey> - - <description> - <![CDATA[Abstract classes should be named 'AbstractXXX'. Example : - <pre> -public abstract class Foo { // should be AbstractFoo -} - </pre>]]></description> - </rule> - - <rule key="NoPackage" > -<priority>MAJOR</priority> - <name><![CDATA[No package]]></name> + + + </rule> + + <rule key="NoPackage"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/naming.xml/NoPackage]]></configKey> - - <description> - <![CDATA[Detects when a class or interface does not have a package definition. Example : - <pre> -// no package declaration -public class ClassInDefaultPackage { -} - </pre>]]></description> + + </rule> - <rule key="PackageCase" > -<priority>MAJOR</priority> - <name><![CDATA[Package case]]></name> + <rule key="PackageCase"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/naming.xml/PackageCase]]></configKey> - - <description> - <![CDATA[ Detects when a package definition contains upper case characters. Example : -<pre> -package com.MyCompany; // <- should be lower case name -public class SomeClass { -} -</pre>]]></description> - </rule> - - <rule key="ByteInstantiation" > -<priority>MAJOR</priority> - <name><![CDATA[Java5 migration - Byte instantiation]]></name> + + + </rule> + + <rule key="ByteInstantiation"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/migrating.xml/ByteInstantiation]]></configKey> - <description> - <![CDATA[In JDK 1.5, calling new Byte() causes memory allocation. Byte.valueOf() is more memory friendly. Example : -<pre> -public class Foo { -private Byte i = new Byte(0); // change to Byte i = -Byte.valueOf(0); -} -</pre>]]></description> + </rule> - <rule key="ShortInstantiation" > -<priority>MAJOR</priority> - <name><![CDATA[Java5 migration - Short instantiation]]></name> + <rule key="ShortInstantiation"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/migrating.xml/ShortInstantiation]]></configKey> - <description> - <![CDATA[In JDK 1.5, calling new Short() causes memory allocation. Short.valueOf() is more memory friendly. Example : - <pre> -public class Foo { -private Short i = new Short(0); // change to Short i = -Short.valueOf(0); -} - </pre>]]></description> + </rule> - <rule key="LongInstantiation" > -<priority>MAJOR</priority> - <name><![CDATA[Java5 migration - Long instantiation]]></name> - <configKey><![CDATA[rulesets/migrating.xml/LongInstantiation]]></configKey> + <rule key="LongInstantiation"> + <priority>MAJOR</priority> - <description> - <![CDATA[In JDK 1.5, calling new Long() causes memory allocation. Long.valueOf() is more memory friendly. Example : - <pre> -public class Foo { -private Long i = new Long(0); // change to Long i = -Long.valueOf(0); -} - </pre>]]></description> - </rule> + <configKey><![CDATA[rulesets/migrating.xml/LongInstantiation]]></configKey> - <rule key="ProperCloneImplementation" > -<priority>CRITICAL</priority> - <name><![CDATA[Proper clone implementation]]></name> - <configKey><![CDATA[rulesets/clone.xml/ProperCloneImplementation]]></configKey> - <description> - <![CDATA[Object clone() should be implemented with super.clone(). Example : - <pre> -class Foo{ - public Object clone(){ - return new Foo(); // This is bad - } -} - </pre>]]></description> </rule> + <rule key="ProperCloneImplementation"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/clone.xml/ProperCloneImplementation]]></configKey> - + </rule> <!-- PMD <= 4.1.1 --> - <rule key="EmptyFinalizer" > -<priority>MAJOR</priority> - <name><![CDATA[Empty Finalizer]]></name> + <rule key="EmptyFinalizer"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/finalizers.xml/EmptyFinalizer]]></configKey> - - <description><![CDATA[If the finalize() method is empty, then it does not need to exist.]]></description> + + </rule> - <rule key="FinalizeOnlyCallsSuperFinalize" > -<priority>MAJOR</priority> - <name><![CDATA[Finalize Only Calls Super Finalize]]></name> + <rule key="FinalizeOnlyCallsSuperFinalize"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize]]></configKey> - - <description><![CDATA[If the finalize() is implemented, it should do something besides just calling super.finalize().]]></description> + + </rule> - <rule key="FinalizeOverloaded" > -<priority>MAJOR</priority> - <name><![CDATA[Finalize Overloaded]]></name> + <rule key="FinalizeOverloaded"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/finalizers.xml/FinalizeOverloaded]]></configKey> - - <description> - <![CDATA[Methods named finalize() should not have parameters. It is confusing and probably a bug to overload finalize(). It will not be called by the VM.]]></description> + + </rule> - <rule key="FinalizeDoesNotCallSuperFinalize" > -<priority>MAJOR</priority> - <name><![CDATA[Finalize Does Not Call Super Finalize]]></name> + <rule key="FinalizeDoesNotCallSuperFinalize"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize]]></configKey> - - <description><![CDATA[If the finalize() is implemented, its last action should be to call super.finalize.]]></description> + + </rule> - <rule key="FinalizeShouldBeProtected" > -<priority>MAJOR</priority> - <name><![CDATA[Finalize Should Be Protected]]></name> + <rule key="FinalizeShouldBeProtected"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/finalizers.xml/FinalizeShouldBeProtected]]></configKey> - - <description><![CDATA[If you override finalize(), make it protected. If you make it public, other classes may call it.]]></description> + + </rule> - <rule key="AvoidCallingFinalize" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Calling Finalize]]></name> + <rule key="AvoidCallingFinalize"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/finalizers.xml/AvoidCallingFinalize]]></configKey> - - <description> - <![CDATA[Object.finalize() is called by the garbage collector on an object when garbage collection determines that there are no more references to the object. ]]></description> + + </rule> - <rule key="DontNestJsfInJstlIteration" > -<priority>MAJOR</priority> - <name><![CDATA[Dont Nest Jsf In Jstl Iteration]]></name> + <rule key="DontNestJsfInJstlIteration"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic-jsf.xml/DontNestJsfInJstlIteration]]></configKey> - - <description><![CDATA[Do not nest JSF component custom actions inside a custom action that iterates over its body.]]></description> + + </rule> - <rule key="UnusedPrivateField" > -<priority>MAJOR</priority> - <name><![CDATA[Unused Private Field]]></name> + <rule key="UnusedPrivateField"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/unusedcode.xml/UnusedPrivateField]]></configKey> - - <description><![CDATA[Detects when a private field is declared and/or assigned a value, but not used.]]></description> + + </rule> - <rule key="UnusedLocalVariable" > -<priority>MAJOR</priority> - <name><![CDATA[Unused local variable]]></name> + <rule key="UnusedLocalVariable"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/unusedcode.xml/UnusedLocalVariable]]></configKey> - - <description><![CDATA[Detects when a local variable is declared and/or assigned, but not used.]]></description> + + </rule> - <rule key="UnusedPrivateMethod" > -<priority>MAJOR</priority> - <name><![CDATA[Unused private method]]></name> + <rule key="UnusedPrivateMethod"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/unusedcode.xml/UnusedPrivateMethod]]></configKey> - - <description><![CDATA[Unused Private Method detects when a private method is declared but is unused. This PMD rule should be switched off and replaced by its equivalent from Squid that is more effective : it generates less false-positives and detects more dead code.]]></description> + + </rule> - <rule key="UnusedFormalParameter" > -<priority>MAJOR</priority> - <name><![CDATA[Unused formal parameter]]></name> + <rule key="UnusedFormalParameter"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/unusedcode.xml/UnusedFormalParameter]]></configKey> - - <description><![CDATA[Avoid passing parameters to methods or constructors and then not using those parameters. ]]></description> + + </rule> - <rule key="UnnecessaryConstructor" > -<priority>MAJOR</priority> - <name><![CDATA[Unnecessary constructor]]></name> + <rule key="UnnecessaryConstructor"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/controversial.xml/UnnecessaryConstructor]]></configKey> - - <description> - <![CDATA[This rule detects when a constructor is not necessary; i.e., when there's only one constructor, it's public, has an empty body, and takes no arguments.]]></description> + + </rule> - <rule key="NullAssignment" > -<priority>MAJOR</priority> - <name><![CDATA[Null Assignment]]></name> + <rule key="NullAssignment"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/controversial.xml/NullAssignment]]></configKey> - - <description> - <![CDATA[Assigning a null to a variable (outside of its declaration) is usually bad form. Some times, the assignment is an indication that the programmer doesn't completely understand what is going on in the code. NOTE: This sort of assignment may in rare cases be useful to encourage garbage collection. If that's what you're using it for, by all means, disregard this rule :-)]]></description> + + </rule> - <rule key="OnlyOneReturn" > -<priority>MINOR</priority> - <name><![CDATA[Only One Return]]></name> + <rule key="OnlyOneReturn"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/controversial.xml/OnlyOneReturn]]></configKey> - - <description><![CDATA[A method should have only one exit point, and that should be the last statement in the method.]]></description> + + </rule> - <rule key="UnusedModifier" > -<priority>INFO</priority> - <name><![CDATA[Unused Modifier]]></name> + <rule key="UnusedModifier"> + <priority>INFO</priority> + <configKey><![CDATA[rulesets/controversial.xml/UnusedModifier]]></configKey> - - <description> - <![CDATA[Fields in interfaces are automatically public static final, and methods are public abstract. Classes or interfaces nested in an interface are automatically public and static (all nested interfaces are automatically static). For historical reasons, modifiers which are implied by the context are accepted by the compiler, but are superfluous.]]></description> + + </rule> - <rule key="AssignmentInOperand" > -<priority>MAJOR</priority> - <name><![CDATA[Assignment In Operand]]></name> + <rule key="AssignmentInOperand"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/controversial.xml/AssignmentInOperand]]></configKey> - - <description><![CDATA[Avoid assignments in operands; this can make code more complicated and harder to read.]]></description> + + </rule> - <rule key="AtLeastOneConstructor" > -<priority>MAJOR</priority> - <name><![CDATA[At Least One Constructor]]></name> + <rule key="AtLeastOneConstructor"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/controversial.xml/AtLeastOneConstructor]]></configKey> - - <description><![CDATA[Each class should declare at least one constructor.]]></description> + + </rule> - <rule key="DontImportSun" > -<priority>MINOR</priority> - <name><![CDATA[Dont Import Sun]]></name> + <rule key="DontImportSun"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/controversial.xml/DontImportSun]]></configKey> - <description><![CDATA[Avoid importing anything from the 'sun.*' packages. These packages are not portable and are likely to change.]]></description> + </rule> - <rule key="SuspiciousOctalEscape" > -<priority>MAJOR</priority> - <name><![CDATA[Suspicious Octal Escape]]></name> + <rule key="SuspiciousOctalEscape"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/controversial.xml/SuspiciousOctalEscape]]></configKey> - - <description> - <![CDATA[A suspicious octal escape sequence was found inside a String literal. The Java language specification (section 3.10.6) says an octal escape sequence inside a literal String shall consist of a backslash followed by: OctalDigit | OctalDigit OctalDigit | ZeroToThree OctalDigit OctalDigit Any octal escape sequence followed by non-octal digits can be confusing, e.g. "\038" is interpreted as the octal escape sequence "\03" followed by the literal character 8.]]></description> + + </rule> - <rule key="CallSuperInConstructor" > -<priority>MINOR</priority> - <name><![CDATA[Call Super In Constructor]]></name> + <rule key="CallSuperInConstructor"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/controversial.xml/CallSuperInConstructor]]></configKey> - - <description> - <![CDATA[It is a good practice to call super() in a constructor. If super() is not called but another constructor (such as an overloaded constructor) is called, this rule will not report it.]]></description> + + </rule> - <rule key="SingularField" > -<priority>MINOR</priority> - <name><![CDATA[Singular Field]]></name> + <rule key="SingularField"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/design.xml/SingularField]]></configKey> - - <description><![CDATA[A field that's only used by one method could perhaps be replaced by a local variable.]]></description> + + </rule> - <rule key="DefaultPackage" > -<priority>MINOR</priority> - <name><![CDATA[Default Package]]></name> + <rule key="DefaultPackage"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/controversial.xml/DefaultPackage]]></configKey> - - <description><![CDATA[Use explicit scoping instead of the default package private level.]]></description> + + </rule> - <rule key="BooleanInversion" > -<priority>MAJOR</priority> - <name><![CDATA[Boolean Inversion]]></name> + <rule key="BooleanInversion"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/controversial.xml/BooleanInversion]]></configKey> - <description> - <![CDATA[Use bitwise inversion to invert boolean values - it's the fastest way to do this. See http://www.javaspecialists.co.za/archive/newsletter.do?issue=042&locale=en_US for specific details]]></description> + </rule> - <rule key="DataflowAnomalyAnalysis" > -<priority>MAJOR</priority> - <name><![CDATA[Dataflow Anomaly Analysis]]></name> + <rule key="DataflowAnomalyAnalysis"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/controversial.xml/DataflowAnomalyAnalysis]]></configKey> - - <description> - <![CDATA[The dataflow analysis tracks local definitions, undefinitions and references to variables on different paths on the data flow. From those informations there can be found various problems. 1. UR - Anomaly: There is a reference to a variable that was not defined before. This is a bug and leads to an error. 2. DU - Anomaly: A recently defined variable is undefined. These anomalies may appear in normal source text. 3. DD - Anomaly: A recently defined variable is redefined. This is ominous but don't have to be a bug. ]]></description> + + <param key="maxviolations" type="i"> - <description><![CDATA[The maximum number of violations per class. Default is 100.]]></description> + </param> <param key="maxpaths" type="i"> - <description> - <![CDATA[The maximum number of checked paths per method. A lower value will increase the performance of the rule but may decrease the number of found anomalies. Default is 1000.]]></description> + </param> </rule> - <rule key="CouplingBetweenObjects" > -<priority>MAJOR</priority> - <name><![CDATA[Coupling between objects]]></name> + <rule key="CouplingBetweenObjects"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/coupling.xml/CouplingBetweenObjects]]></configKey> - - <description> - <![CDATA[This rule counts unique attributes, local variables and return types within an object. A number higher than specified threshold can indicate a high degree of coupling.]]></description> + + <param key="threshold" type="i"> - <description><![CDATA[The unique type reporting threshold. Default is 20.]]></description> + </param> </rule> - <rule key="ExcessiveImports" > -<priority>MAJOR</priority> - <name><![CDATA[Coupling - excessive imports]]></name> + <rule key="ExcessiveImports"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/coupling.xml/ExcessiveImports]]></configKey> - - <description> - <![CDATA[A high number of imports can indicate a high degree of coupling within an object. Rule counts the number of unique imports and reports a violation if the count is above the user defined threshold.]]></description> + + <param key="minimum" type="i"> - <description><![CDATA[The import count reporting threshold. Default is 30.]]></description> + </param> </rule> - <rule key="LooseCoupling" > -<priority>MAJOR</priority> - <name><![CDATA[Loose coupling]]></name> + <rule key="LooseCoupling"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/coupling.xml/LooseCoupling]]></configKey> - - <description><![CDATA[Avoid using implementation types (i.e., HashSet); use the interface (i.e, Set) instead]]></description> + + </rule> - <rule key="MethodArgumentCouldBeFinal" > -<priority>MINOR</priority> - <name><![CDATA[Method Argument Could Be Final]]></name> + <rule key="MethodArgumentCouldBeFinal"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/optimizations.xml/MethodArgumentCouldBeFinal]]></configKey> - <description><![CDATA[A method argument that is never assigned can be declared final.]]></description> + </rule> - <rule key="AvoidInstantiatingObjectsInLoops" > -<priority>MINOR</priority> - <name><![CDATA[Avoid instantiating objects in loops]]></name> + <rule key="AvoidInstantiatingObjectsInLoops"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops]]></configKey> - <description><![CDATA[Detects when a new object is created inside a loop]]></description> + </rule> - <rule key="UseArrayListInsteadOfVector" > -<priority>MAJOR</priority> - <name><![CDATA[Use Array List Instead Of Vector]]></name> + <rule key="UseArrayListInsteadOfVector"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/optimizations.xml/UseArrayListInsteadOfVector]]></configKey> - <description><![CDATA[ArrayList is a much better Collection implementation than Vector.]]></description> + </rule> - <rule key="SimplifyStartsWith" > -<priority>MINOR</priority> - <name><![CDATA[Simplify Starts With]]></name> + <rule key="SimplifyStartsWith"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/optimizations.xml/SimplifyStartsWith]]></configKey> - <description><![CDATA[Since it passes in a literal of length 1, this call to String.startsWith can be rewritten using String.charAt(0) to save some time.]]></description> + </rule> - <rule key="UseStringBufferForStringAppends" > -<priority>MAJOR</priority> - <name><![CDATA[Use String Buffer For String Appends]]></name> + <rule key="UseStringBufferForStringAppends"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/optimizations.xml/UseStringBufferForStringAppends]]></configKey> - <description><![CDATA[Finds usages of += for appending strings.]]></description> + </rule> - <rule key="UseArraysAsList" > -<priority>MAJOR</priority> - <name><![CDATA[Use Arrays As List]]></name> + <rule key="UseArraysAsList"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/optimizations.xml/UseArraysAsList]]></configKey> - <description> - <![CDATA[The class java.util.Arrays has a asList method that should be use when you want to create a new List from an array of objects. It is faster than executing a loop to cpy all the elements of the array one by one]]></description> + </rule> - <rule key="AvoidArrayLoops" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Array Loops]]></name> + <rule key="AvoidArrayLoops"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/optimizations.xml/AvoidArrayLoops]]></configKey> - <description><![CDATA[Instead of copying data between two arrays, use System.arrayCopy method]]></description> + </rule> - <rule key="UnnecessaryWrapperObjectCreation" > -<priority>MAJOR</priority> - <name><![CDATA[Unnecessary Wrapper Object Creation]]></name> + <rule key="UnnecessaryWrapperObjectCreation"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/optimizations.xml/UnnecessaryWrapperObjectCreation]]></configKey> - <description><![CDATA[Parsing method should be called directy instead. ]]></description> + </rule> - <rule key="UseProperClassLoader" > -<priority>CRITICAL</priority> - <name><![CDATA[Use Proper Class Loader]]></name> + <rule key="UseProperClassLoader"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/j2ee.xml/UseProperClassLoader]]></configKey> - - <description><![CDATA[In J2EE getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead.]]></description> + + </rule> - <rule key="EmptyCatchBlock" > -<priority>CRITICAL</priority> - <name><![CDATA[Empty Catch Block]]></name> + <rule key="EmptyCatchBlock"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/basic.xml/EmptyCatchBlock]]></configKey> - - <description> - <![CDATA[Empty Catch Block finds instances where an exception is caught, but nothing is done. In most circumstances, this swallows an exception which should either be acted on or reported.]]></description> + + <param key="allowCommentedBlocks" type="b"> - <description><![CDATA[Empty blocks containing comments will be skipped. Default is false.]]></description> + </param> </rule> - <rule key="EmptyIfStmt" > -<priority>CRITICAL</priority> - <name><![CDATA[Empty If Stmt]]></name> + <rule key="EmptyIfStmt"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/basic.xml/EmptyIfStmt]]></configKey> - - <description><![CDATA[Empty If Statement finds instances where a condition is checked but nothing is done about it.]]></description> + + </rule> - <rule key="EmptyWhileStmt" > -<priority>CRITICAL</priority> - <name><![CDATA[Empty While Stmt]]></name> + <rule key="EmptyWhileStmt"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/basic.xml/EmptyWhileStmt]]></configKey> - - <description> - <![CDATA[Empty While Statement finds all instances where a while statement does nothing. If it is a timing loop, then you should use Thread.sleep() for it; if it's a while loop that does a lot in the exit expression, rewrite it to make it clearer.]]></description> + + </rule> - <rule key="EmptyTryBlock" > -<priority>MAJOR</priority> - <name><![CDATA[Empty Try Block]]></name> + <rule key="EmptyTryBlock"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic.xml/EmptyTryBlock]]></configKey> - - <description><![CDATA[Avoid empty try blocks - what's the point?]]></description> + + </rule> - <rule key="EmptyFinallyBlock" > -<priority>CRITICAL</priority> - <name><![CDATA[Empty Finally Block]]></name> + <rule key="EmptyFinallyBlock"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/basic.xml/EmptyFinallyBlock]]></configKey> - - <description><![CDATA[Avoid empty finally blocks - these can be deleted.]]></description> + + </rule> - <rule key="EmptySwitchStatements" > -<priority>MAJOR</priority> - <name><![CDATA[Empty Switch Statements]]></name> + <rule key="EmptySwitchStatements"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic.xml/EmptySwitchStatements]]></configKey> - - <description><![CDATA[Avoid empty switch statements.]]></description> + + </rule> - <rule key="JumbledIncrementer" > -<priority>MAJOR</priority> - <name><![CDATA[Jumbled Incrementer]]></name> + <rule key="JumbledIncrementer"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic.xml/JumbledIncrementer]]></configKey> - - <description><![CDATA[Avoid jumbled loop incrementers - it's usually a mistake, and it's confusing even if it's what's intended. - <br>Example : - <pre> -public class JumbledIncrementerRule1 { - public void foo() { - for (int i = 0; i < 10; i++) { - for (int k = 0; k < 20; i++) { - System.out.println("Hello"); - } - } - } -}</pre>]]></description> - </rule> - <rule key="ForLoopShouldBeWhileLoop" > -<priority>MINOR</priority> - <name><![CDATA[For Loop Should Be While Loop]]></name> + + + </rule> + <rule key="ForLoopShouldBeWhileLoop"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/basic.xml/ForLoopShouldBeWhileLoop]]></configKey> - - <description><![CDATA[Some for loops can be simplified to while loops - this makes them more concise.]]></description> + + </rule> - <rule key="UnnecessaryConversionTemporary" > -<priority>MAJOR</priority> - <name><![CDATA[Unnecessary Conversion Temporary]]></name> + <rule key="UnnecessaryConversionTemporary"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic.xml/UnnecessaryConversionTemporary]]></configKey> - <description><![CDATA[Avoid unnecessary temporaries when converting primitives to Strings]]></description> + </rule> - <rule key="ReturnFromFinallyBlock" > -<priority>MAJOR</priority> - <name><![CDATA[Return From Finally Block]]></name> + <rule key="ReturnFromFinallyBlock"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic.xml/ReturnFromFinallyBlock]]></configKey> - - <description><![CDATA[Avoid returning from a finally block - this can discard exceptions.]]></description> + + </rule> - <rule key="EmptySynchronizedBlock" > -<priority>CRITICAL</priority> - <name><![CDATA[Empty Synchronized Block]]></name> + <rule key="EmptySynchronizedBlock"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/basic.xml/EmptySynchronizedBlock]]></configKey> - - <description><![CDATA[Avoid empty synchronized blocks - they're useless.]]></description> + + </rule> - <rule key="UnnecessaryReturn" > -<priority>MINOR</priority> - <name><![CDATA[Unnecessary Return]]></name> + <rule key="UnnecessaryReturn"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/basic.xml/UnnecessaryReturn]]></configKey> - - <description><![CDATA[Avoid unnecessary return statements]]></description> + + </rule> - <rule key="EmptyStaticInitializer" > -<priority>MAJOR</priority> - <name><![CDATA[Empty Static Initializer]]></name> + <rule key="EmptyStaticInitializer"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic.xml/EmptyStaticInitializer]]></configKey> - - <description><![CDATA[An empty static initializer was found.]]></description> + + </rule> - <rule key="UnconditionalIfStatement" > -<priority>CRITICAL</priority> - <name><![CDATA[Unconditional If Statement]]></name> + <rule key="UnconditionalIfStatement"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/basic.xml/UnconditionalIfStatement]]></configKey> - - <description><![CDATA[Do not use if statements that are always true or always false.]]></description> + + </rule> - <rule key="EmptyStatementNotInLoop" > -<priority>MAJOR</priority> - <name><![CDATA[Empty Statement Not In Loop]]></name> + <rule key="EmptyStatementNotInLoop"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic.xml/EmptyStatementNotInLoop]]></configKey> - - <description> - <![CDATA[An empty statement (aka a semicolon by itself) that is not used as the sole body of a for loop or while loop is probably a bug. It could also be a double semicolon, which is useless and should be removed.]]></description> + + </rule> - <rule key="BooleanInstantiation" > -<priority>MAJOR</priority> - <name><![CDATA[Boolean Instantiation]]></name> + <rule key="BooleanInstantiation"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic.xml/BooleanInstantiation]]></configKey> - <description><![CDATA[Avoid instantiating Boolean objects; you can reference Boolean.TRUE, Boolean.FALSE, or call Boolean.valueOf() instead.]]></description> + </rule> - <rule key="UnnecessaryFinalModifier" > -<priority>INFO</priority> - <name><![CDATA[Unnecessary Final Modifier]]></name> + <rule key="UnnecessaryFinalModifier"> + <priority>INFO</priority> + <configKey><![CDATA[rulesets/basic.xml/UnnecessaryFinalModifier]]></configKey> - - <description><![CDATA[When a class has the final modifier, all the methods are automatically final.]]></description> + + </rule> - <rule key="CollapsibleIfStatements" > -<priority>MINOR</priority> - <name><![CDATA[Collapsible If Statements]]></name> + <rule key="CollapsibleIfStatements"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/basic.xml/CollapsibleIfStatements]]></configKey> - - <description><![CDATA[Sometimes two 'if' statements can be consolidated by separating their conditions with a boolean short-circuit operator.]]></description> + + </rule> - <rule key="UselessOverridingMethod" > -<priority>MAJOR</priority> - <name><![CDATA[Useless Overriding Method]]></name> + <rule key="UselessOverridingMethod"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic.xml/UselessOverridingMethod]]></configKey> - - <description><![CDATA[The overriding method merely calls the same method defined in a superclass]]></description> + + <param key="ignoreAnnotations" type="b"> - <description><![CDATA[Ignore annotations. Default is false.]]></description> + </param> </rule> - <rule key="ClassCastExceptionWithToArray" > -<priority>MAJOR</priority> - <name><![CDATA[Class Cast Exception With To Array]]></name> + <rule key="ClassCastExceptionWithToArray"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic.xml/ClassCastExceptionWithToArray]]></configKey> - - <description> - <![CDATA[if you need to get an array of a class from your Collection, you should pass an array of the desidered class as the parameter of the toArray method. Otherwise you will get a ClassCastException.]]></description> + + </rule> - <rule key="AvoidDecimalLiteralsInBigDecimalConstructor" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Decimal Literals In Big Decimal Constructor]]></name> + <rule key="AvoidDecimalLiteralsInBigDecimalConstructor"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic.xml/AvoidDecimalLiteralsInBigDecimalConstructor]]></configKey> - - <description> - <![CDATA[One might assume that new BigDecimal(.1) is exactly equal to .1, but it is actually equal to .1000000000000000055511151231257827021181583404541015625. This is so because .1 cannot be represented exactly as a double (or, for that matter, as a binary fraction of any finite length). Thus, the long value that is being passed in to the constructor is not exactly equal to .1, appearances notwithstanding. The (String) constructor, on the other hand, is perfectly predictable: 'new BigDecimal(.1)' is exactly equal to .1, as one would expect. Therefore, it is generally recommended that the (String) constructor be used in preference to this one.]]></description> + + </rule> - <rule key="UselessOperationOnImmutable" > -<priority>CRITICAL</priority> - <name><![CDATA[Useless Operation On Immutable]]></name> + <rule key="UselessOperationOnImmutable"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/basic.xml/UselessOperationOnImmutable]]></configKey> - - <description> - <![CDATA[An operation on an Immutable object (BigDecimal or BigInteger) won't change the object itself. The result of the operation is a new object. Therefore, ignoring the operation result is an error.]]></description> + + </rule> - <rule key="MisplacedNullCheck" > -<priority>CRITICAL</priority> - <name><![CDATA[Misplaced Null Check]]></name> + <rule key="MisplacedNullCheck"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/basic.xml/MisplacedNullCheck]]></configKey> - - <description> - <![CDATA[The null check here is misplaced. if the variable is null you'll get a NullPointerException. - Either the check is useless (the variable will never be null) or it's incorrect. - <br>Example : - <pre> -if (object1!=null && object2.equals(object1)) { - ... -} - </pre>]]></description> - </rule> - <rule key="UnusedNullCheckInEquals" > -<priority>MAJOR</priority> - <name><![CDATA[Unused Null Check In Equals]]></name> + + + </rule> + <rule key="UnusedNullCheckInEquals"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic.xml/UnusedNullCheckInEquals]]></configKey> - - <description> - <![CDATA[After checking an object reference for null, you should invoke equals() on that object rather than passing it to another object's equals() method.]]></description> + + </rule> - <rule key="AvoidThreadGroup" > -<priority>CRITICAL</priority> - <name><![CDATA[Avoid Thread Group]]></name> + <rule key="AvoidThreadGroup"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/basic.xml/AvoidThreadGroup]]></configKey> - - <description><![CDATA[Avoid using ThreadGroup; although it is intended to be used in a threaded environment it contains methods that are not thread safe.]]></description> + + </rule> - <rule key="BrokenNullCheck" > -<priority>CRITICAL</priority> - <name><![CDATA[Broken Null Check]]></name> + <rule key="BrokenNullCheck"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/basic.xml/BrokenNullCheck]]></configKey> - - <description> - <![CDATA[The null check is broken since it will throw a Nullpointer itself. The reason is that a method is called on the object when it is null. It is likely that you used || instead of && or vice versa.]]></description> + + </rule> - <rule key="BigIntegerInstantiation" > -<priority>MAJOR</priority> - <name><![CDATA[Big Integer Instantiation]]></name> + <rule key="BigIntegerInstantiation"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic.xml/BigIntegerInstantiation]]></configKey> - <description> - <![CDATA[Don't create instances of already existing BigInteger (BigInteger.ZERO, BigInteger.ONE) and for 1.5 on, BigInteger.TEN and BigDecimal (BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN)]]></description> + </rule> - <rule key="AvoidUsingOctalValues" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Using Octal Values]]></name> + <rule key="AvoidUsingOctalValues"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic.xml/AvoidUsingOctalValues]]></configKey> - - <description><![CDATA[Integer literals should not start with zero. Zero means that the rest of literal will be interpreted as an octal value. ]]></description> + + </rule> - <rule key="UseSingleton" > -<priority>MAJOR</priority> - <name><![CDATA[Use Singleton]]></name> + <rule key="UseSingleton"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/UseSingleton]]></configKey> - <description> - <![CDATA[If you have a class that has nothing but static methods, consider making it a Singleton. Note that this doesn't apply to abstract classes, since their subclasses may well include non-static methods. Also, if you want this class to be a Singleton, remember to add a private constructor to prevent instantiation.]]></description> + </rule> - <rule key="AvoidDeeplyNestedIfStmts" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Deeply Nested If Stmts]]></name> + <rule key="AvoidDeeplyNestedIfStmts"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/AvoidDeeplyNestedIfStmts]]></configKey> - - <description><![CDATA[Deeply nested if..then statements are hard to read.]]></description> + + <param key="problemDepth" type="i"> - <description><![CDATA[The if statement depth reporting threshold. Default is 3.]]></description> + </param> </rule> - <rule key="AvoidReassigningParameters" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Reassigning Parameters]]></name> + <rule key="AvoidReassigningParameters"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/AvoidReassigningParameters]]></configKey> - - <description><![CDATA[Reassigning values to parameters is a questionable practice. Use a temporary local variable instead.]]></description> + + </rule> - <rule key="SwitchDensity" > -<priority>MAJOR</priority> - <name><![CDATA[Switch Density]]></name> + <rule key="SwitchDensity"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/SwitchDensity]]></configKey> - - <description> - <![CDATA[A high ratio of statements to labels in a switch statement implies that the switch statement is doing too much work. Consider moving the statements into new methods, or creating subclasses based on the switch variable.]]></description> + + <param key="minimum" type="i"> - <description><![CDATA[The switch statement ratio reporting threshold. Default is 10.]]></description> + </param> </rule> - <rule key="ConstructorCallsOverridableMethod" > -<priority>MAJOR</priority> - <name><![CDATA[Constructor Calls Overridable Method]]></name> + <rule key="ConstructorCallsOverridableMethod"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/ConstructorCallsOverridableMethod]]></configKey> - - <description> - <![CDATA[Calling overridable methods during construction poses a risk of invoking methods on an incompletely constructed object - and can be difficult to discern. It may leave the sub-class unable to construct its superclass or forced to replicate - the construction process completely within itself, losing the ability to call super(). - If the default constructor contains a call to an overridable method, the subclass may be completely uninstantiable. - Note that this includes method calls throughout the control flow graph - i.e., if a constructor Foo() calls - a private method bar() that calls a public method buz(), this denotes a problem. - <br/>Example : -<pre> -public class SeniorClass { - public SeniorClass(){ - toString(); //may throw NullPointerException if overridden - } - public String toString(){ - return "IAmSeniorClass"; - } -} -public class JuniorClass extends SeniorClass { - private String name; - public JuniorClass(){ - super(); //Automatic call leads to NullPointerException - name = "JuniorClass"; - } - public String toString(){ - return name.toUpperCase(); - } -} -</pre>]]></description> - </rule> - <rule key="AccessorClassGeneration" > -<priority>MAJOR</priority> - <name><![CDATA[Accessor Class Generation]]></name> + + + </rule> + <rule key="AccessorClassGeneration"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/AccessorClassGeneration]]></configKey> - - <description> - <![CDATA[Instantiation by way of private constructors from outside of the constructor's class often causes the generation of an accessor. A factory method, or non-privitization of the constructor can eliminate this situation. The generated class file is actually an interface. It gives the accessing class the ability to invoke a new hidden package scope constructor that takes the interface as a supplementary parameter. This turns a private constructor effectively into one with package scope, and is challenging to discern.]]></description> + + </rule> - <rule key="FinalFieldCouldBeStatic" > -<priority>MINOR</priority> - <name><![CDATA[Final Field Could Be Static]]></name> + <rule key="FinalFieldCouldBeStatic"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/design.xml/FinalFieldCouldBeStatic]]></configKey> - <description><![CDATA[If a final field is assigned to a compile-time constant, it could be made static, thus saving overhead in each object at runtime.]]></description> + </rule> - <rule key="CloseResource" > -<priority>MAJOR</priority> - <name><![CDATA[Close Resource]]></name> + <rule key="CloseResource"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/CloseResource]]></configKey> - - <description><![CDATA[Ensure that resources (like Connection, Statement, and ResultSet objects) are always closed after use. It does this by looking for code patterned like : -<pre> -Connection c = openConnection(); -try { - // do stuff, and maybe catch something -} finally { - c.close(); -} -</pre> -]]></description> + + <param key="types" type="s"> - <description><![CDATA[Resources to check. Default value is 'Connection,Statement,ResultSet',]]></description> + </param> - <param key="closeTargets" type="s"> - <description><![CDATA[Methods which may close this resource. Default is 'close'.]]></description> + <param key="closeTargets" type="s"> + </param> </rule> - <rule key="NonStaticInitializer" > -<priority>MAJOR</priority> - <name><![CDATA[Non Static Initializer]]></name> + <rule key="NonStaticInitializer"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/NonStaticInitializer]]></configKey> - - <description> - <![CDATA[A nonstatic initializer block will be called any time a constructor is invoked (just prior to invoking the constructor). While this is a valid language construct, it is rarely used and is confusing. Example :<br/><code>public class MyClass {<br/>// this block gets run before any call to a constructor {<br/>System.out.println("I am about to construct myself");<br/>}<br/>}</code>]]></description> + + </rule> - <rule key="NonCaseLabelInSwitchStatement" > -<priority>MAJOR</priority> - <name><![CDATA[Non Case Label In Switch Statement]]></name> + <rule key="NonCaseLabelInSwitchStatement"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/NonCaseLabelInSwitchStatement]]></configKey> - - <description> - <![CDATA[A non-case label (e.g. a named break/continue label) was present in a switch statement. This legal, but confusing. It is easy to mix up the case labels and the non-case labels.]]></description> + + </rule> - <rule key="OptimizableToArrayCall" > -<priority>MAJOR</priority> - <name><![CDATA[Optimizable To Array Call]]></name> + <rule key="OptimizableToArrayCall"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/OptimizableToArrayCall]]></configKey> - <description><![CDATA[A call to Collection.toArray can use the Collection's size vs an empty Array of the desired type.]]></description> + </rule> - <rule key="BadComparison" > -<priority>MAJOR</priority> - <name><![CDATA[Bad Comparison]]></name> + <rule key="BadComparison"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/BadComparison]]></configKey> - - <description><![CDATA[Avoid equality comparisons with Double.NaN - these are likely to be logic errors.]]></description> + + </rule> - <rule key="EqualsNull" > -<priority>CRITICAL</priority> - <name><![CDATA[Equals Null]]></name> + <rule key="EqualsNull"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/design.xml/EqualsNull]]></configKey> - - <description><![CDATA[Inexperienced programmers sometimes confuse comparison concepts and use equals() to compare to null.]]></description> + + </rule> - <rule key="ConfusingTernary" > -<priority>MAJOR</priority> - <name><![CDATA[Confusing Ternary]]></name> + <rule key="ConfusingTernary"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/ConfusingTernary]]></configKey> - - <description> - <![CDATA[In an if expression with an else clause, avoid negation in the test. For example, rephrase: if (x != y) diff(); else same(); as: if (x == y) same(); else diff(); Most if (x != y) cases without an else are often return cases, so consistent use of this rule makes the code easier to read. Also, this resolves trivial ordering problems, such as does the error case go first? or does the common case go first?.]]></description> + + </rule> - <rule key="InstantiationToGetClass" > -<priority>MAJOR</priority> - <name><![CDATA[Instantiation To Get Class]]></name> + <rule key="InstantiationToGetClass"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/InstantiationToGetClass]]></configKey> - - <description> - <![CDATA[Avoid instantiating an object just to call getClass() on it; use the .class public member instead. Example : replace <code>Class c = new String().getClass();</code> with <code>Class c = String.class;</code>]]></description> + + </rule> - <rule key="IdempotentOperations" > -<priority>MAJOR</priority> - <name><![CDATA[Idempotent Operations]]></name> + <rule key="IdempotentOperations"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/IdempotentOperations]]></configKey> - <description><![CDATA[Avoid idempotent operations - they are have no effect. Example : <br/><code>int x = 2;<br/> x = x;</code>]]></description> + </rule> - <rule key="SimpleDateFormatNeedsLocale" > -<priority>MAJOR</priority> - <name><![CDATA[Simple Date Format Needs Locale]]></name> + <rule key="SimpleDateFormatNeedsLocale"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/SimpleDateFormatNeedsLocale]]></configKey> - - <description><![CDATA[Be sure to specify a Locale when creating a new instance of SimpleDateFormat.]]></description> + + </rule> - <rule key="ImmutableField" > -<priority>MAJOR</priority> - <name><![CDATA[Immutable Field]]></name> + <rule key="ImmutableField"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/ImmutableField]]></configKey> - - <description> - <![CDATA[Identifies private fields whose values never change once they are initialized either in the declaration of the field or by a constructor. This aids in converting existing classes to immutable classes.]]></description> + + </rule> - <rule key="UseLocaleWithCaseConversions" > -<priority>MAJOR</priority> - <name><![CDATA[Use Locale With Case Conversions]]></name> + <rule key="UseLocaleWithCaseConversions"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/UseLocaleWithCaseConversions]]></configKey> - - <description><![CDATA[When doing a String.toLowerCase()/toUpperCase() call, use a Locale. This avoids problems with certain locales, i.e. Turkish.]]></description> + + </rule> - <rule key="AvoidProtectedFieldInFinalClass" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Protected Field In Final Class]]></name> + <rule key="AvoidProtectedFieldInFinalClass"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/AvoidProtectedFieldInFinalClass]]></configKey> - - <description> - <![CDATA[Do not use protected fields in final classes since they cannot be subclassed. Clarify your intent by using private or package access modifiers instead.]]></description> + + </rule> - <rule key="AssignmentToNonFinalStatic" > -<priority>MAJOR</priority> - <name><![CDATA[Assignment To Non Final Static]]></name> + <rule key="AssignmentToNonFinalStatic"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/AssignmentToNonFinalStatic]]></configKey> - - <description><![CDATA[Identifies a possible unsafe usage of a static field.]]></description> + + </rule> - <rule key="MissingStaticMethodInNonInstantiatableClass" > -<priority>MAJOR</priority> - <name><![CDATA[Missing Static Method In Non Instantiatable Class]]></name> + <rule key="MissingStaticMethodInNonInstantiatableClass"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass]]></configKey> - - <description><![CDATA[A class that has private constructors and does not have any static methods or fields cannot be used.]]></description> + + </rule> - <rule key="AvoidSynchronizedAtMethodLevel" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Synchronized At Method Level]]></name> + <rule key="AvoidSynchronizedAtMethodLevel"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/AvoidSynchronizedAtMethodLevel]]></configKey> - - <description> - <![CDATA[Method level synchronization can backfire when new code is added to the method. Block-level synchronization helps to ensure that only the code that needs synchronization gets it.]]></description> + + </rule> - <rule key="MissingBreakInSwitch" > -<priority>CRITICAL</priority> - <name><![CDATA[Missing Break In Switch]]></name> + <rule key="MissingBreakInSwitch"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/design.xml/MissingBreakInSwitch]]></configKey> - - <description><![CDATA[A switch statement without an enclosed break statement may be a bug.]]></description> + + </rule> - <rule key="UseNotifyAllInsteadOfNotify" > -<priority>MAJOR</priority> - <name><![CDATA[Use Notify All Instead Of Notify]]></name> + <rule key="UseNotifyAllInsteadOfNotify"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/UseNotifyAllInsteadOfNotify]]></configKey> - - <description> - <![CDATA[Thread.notify() awakens a thread monitoring the object. If more than one thread is monitoring, then only one is chosen. The thread chosen is arbitrary; thus it's usually safer to call notifyAll() instead.]]></description> + + </rule> - <rule key="AvoidInstanceofChecksInCatchClause" > -<priority>MINOR</priority> - <name><![CDATA[Avoid Instanceof Checks In Catch Clause]]></name> + <rule key="AvoidInstanceofChecksInCatchClause"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/design.xml/AvoidInstanceofChecksInCatchClause]]></configKey> - - <description><![CDATA[Each caught exception type should be handled in its own catch clause.]]></description> + + </rule> - <rule key="AbstractClassWithoutAbstractMethod" > -<priority>MAJOR</priority> - <name><![CDATA[Abstract Class Without Abstract Method]]></name> + <rule key="AbstractClassWithoutAbstractMethod"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/AbstractClassWithoutAbstractMethod]]></configKey> - - <description> - <![CDATA[The abstract class does not contain any abstract methods. An abstract class suggests an incomplete implementation, which is to be completed by subclasses implementing the abstract methods. If the class is intended to be used as a base class only (not to be instantiated direcly) a protected constructor can be provided prevent direct instantiation.]]></description> + + </rule> - <rule key="SimplifyConditional" > -<priority>MAJOR</priority> - <name><![CDATA[Simplify Conditional]]></name> + <rule key="SimplifyConditional"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/SimplifyConditional]]></configKey> - - <description><![CDATA[No need to check for null before an instanceof; the instanceof keyword returns false when given a null argument.]]></description> + + </rule> - <rule key="CompareObjectsWithEquals" > -<priority>MAJOR</priority> - <name><![CDATA[Compare Objects With Equals]]></name> + <rule key="CompareObjectsWithEquals"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/CompareObjectsWithEquals]]></configKey> - - <description><![CDATA[Use equals() to compare object references; avoid comparing them with ==.]]></description> + + </rule> - <rule key="PositionLiteralsFirstInComparisons" > -<priority>MAJOR</priority> - <name><![CDATA[Position Literals First In Comparisons]]></name> + <rule key="PositionLiteralsFirstInComparisons"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/PositionLiteralsFirstInComparisons]]></configKey> - - <description> - <![CDATA[Position literals first in String comparisons - that way if the String is null you won't get a NullPointerException, it'll just return false.]]></description> + + </rule> - <rule key="UnnecessaryLocalBeforeReturn" > -<priority>MAJOR</priority> - <name><![CDATA[Unnecessary Local Before Return]]></name> + <rule key="UnnecessaryLocalBeforeReturn"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/UnnecessaryLocalBeforeReturn]]></configKey> - <description><![CDATA[Avoid unnecessarily creating local variables]]></description> + </rule> - <rule key="NonThreadSafeSingleton" > -<priority>MAJOR</priority> - <name><![CDATA[Non Thread Safe Singleton]]></name> + <rule key="NonThreadSafeSingleton"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/NonThreadSafeSingleton]]></configKey> - - <description> - <![CDATA[Non-thread safe singletons can result in bad state changes. Eliminate static singletons if possible by instantiating the object directly. Static singletons are usually not needed as only a single instance exists anyway. Other possible fixes are to synchronize the entire method or to use an initialize-on-demand holder class (do not use the double-check idiom). See Effective Java, item 48.]]></description> - <param key="checkNonStaticMethods" type="b" > -<priority>MAJOR</priority> - <description><![CDATA[Do not set this to false and checkNonStaticFields to true. Default is true.]]></description> + + + <param key="checkNonStaticMethods" type="b"> + <priority>MAJOR</priority> + </param> - <param key="checkNonStaticFields" type="b" > -<priority>MAJOR</priority> - <description><![CDATA[Do not set this to true and checkNonStaticMethods to false. Default is false.]]></description> + <param key="checkNonStaticFields" type="b"> + <priority>MAJOR</priority> + </param> </rule> - <rule key="UncommentedEmptyMethod" > -<priority>MAJOR</priority> - <name><![CDATA[Uncommented Empty Method]]></name> + <rule key="UncommentedEmptyMethod"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/UncommentedEmptyMethod]]></configKey> - - <description> - <![CDATA[Uncommented Empty Method finds instances where a method does not contain statements, but there is no comment. By explicitly commenting empty methods it is easier to distinguish between intentional (commented) and unintentional empty methods.]]></description> + + </rule> - <rule key="UncommentedEmptyConstructor" > -<priority>MAJOR</priority> - <name><![CDATA[Uncommented Empty Constructor]]></name> + <rule key="UncommentedEmptyConstructor"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/UncommentedEmptyConstructor]]></configKey> - - <description> - <![CDATA[Uncommented Empty Constructor finds instances where a constructor does not contain statements, but there is no comment. By explicitly commenting empty constructors it is easier to distinguish between intentional (commented) and unintentional empty constructors.]]></description> + + <param key="ignoreExplicitConstructorInvocation" type="b"> - <description><![CDATA[Ignore explicit constructor invocation when deciding whether constructor is empty or not. Default is false.]]></description> + </param> </rule> - <rule key="AvoidConstantsInterface" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Constants Interface]]></name> + <rule key="AvoidConstantsInterface"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/AvoidConstantsInterface]]></configKey> - - <description><![CDATA[An interface should be used only to model a behaviour of a class: using an interface as a container of constants is a poor usage pattern.]]></description> + + </rule> - <rule key="UnsynchronizedStaticDateFormatter" > -<priority>MAJOR</priority> - <name><![CDATA[Unsynchronized Static Date Formatter]]></name> + <rule key="UnsynchronizedStaticDateFormatter"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/UnsynchronizedStaticDateFormatter]]></configKey> - - <description> - <![CDATA[SimpleDateFormat is not synchronized. Sun recomends separate format instances for each thread. If multiple threads must access a static formatter, the formatter must be synchronized either on method or block level.]]></description> + + </rule> - <rule key="PreserveStackTrace" > -<priority>MAJOR</priority> - <name><![CDATA[Preserve Stack Trace]]></name> + <rule key="PreserveStackTrace"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/PreserveStackTrace]]></configKey> - - <description> - <![CDATA[Throwing a new exception from a catch block without passing the original exception into the new Exception will cause the true stack trace to be lost, and can make it difficult to debug effectively.]]></description> + + </rule> - <rule key="UseCollectionIsEmpty" > -<priority>MINOR</priority> - <name><![CDATA[Use Collection Is Empty]]></name> + <rule key="UseCollectionIsEmpty"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/design.xml/UseCollectionIsEmpty]]></configKey> - - <description> - <![CDATA[The isEmpty() method on java.util.Collection is provided to see if a collection has any elements. Comparing the value of size() to 0 merely duplicates existing behavior. ]]></description> + + </rule> - <rule key="MethodReturnsInternalArray" > -<priority>CRITICAL</priority> - <name><![CDATA[Security - Method returns internal array]]></name> + <rule key="MethodReturnsInternalArray"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/sunsecure.xml/MethodReturnsInternalArray]]></configKey> - - <description><![CDATA[Exposing internal arrays directly allows the user to modify some code that could be critical. It is safer to return a copy of the array.]]></description> + + </rule> - <rule key="ArrayIsStoredDirectly" > -<priority>CRITICAL</priority> - <name><![CDATA[Security - Array is stored directly]]></name> + <rule key="ArrayIsStoredDirectly"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/sunsecure.xml/ArrayIsStoredDirectly]]></configKey> - - <description> - <![CDATA[Constructors and methods receiving arrays should clone objects and store the copy. This prevents that future changes from the user affect the internal functionality. ]]></description> + + </rule> - <rule key="AvoidCatchingThrowable" > -<priority>CRITICAL</priority> - <name><![CDATA[Avoid Catching Throwable]]></name> + <rule key="AvoidCatchingThrowable"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/strictexception.xml/AvoidCatchingThrowable]]></configKey> - - <description><![CDATA[This is dangerous because it casts too wide a net; it can catch things like OutOfMemoryError.]]></description> + + </rule> - <rule key="SignatureDeclareThrowsException" > -<priority>MAJOR</priority> - <name><![CDATA[Signature Declare Throws Exception]]></name> + <rule key="SignatureDeclareThrowsException"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/strictexception.xml/SignatureDeclareThrowsException]]></configKey> - - <description> - <![CDATA[It is unclear which exceptions that can be thrown from the methods. It might be difficult to document and understand the vague interfaces. Use either a class derived from RuntimeException or a checked exception.]]></description> + + </rule> - <rule key="ExceptionAsFlowControl" > -<priority>MAJOR</priority> - <name><![CDATA[Exception As Flow Control]]></name> + <rule key="ExceptionAsFlowControl"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/strictexception.xml/ExceptionAsFlowControl]]></configKey> - - <description><![CDATA[Using Exceptions as flow control leads to GOTOish code and obscures true exceptions when debugging.]]></description> + + </rule> - <rule key="AvoidCatchingNPE" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Catching NPE]]></name> + <rule key="AvoidCatchingNPE"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/strictexception.xml/AvoidCatchingNPE]]></configKey> - - <description> - <![CDATA[Code should never throw NPE under normal circumstances. A catch block may hide the original error, causing other more subtle errors in its wake.]]></description> + + </rule> - <rule key="AvoidThrowingRawExceptionTypes" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Throwing Raw Exception Types]]></name> + <rule key="AvoidThrowingRawExceptionTypes"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes]]></configKey> - - <description> - <![CDATA[Avoid throwing certain exception types. Rather than throw a raw RuntimeException, Throwable, Exception, or Error, use a subclassed exception or error instead.]]></description> + + </rule> - <rule key="AvoidThrowingNullPointerException" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Throwing Null Pointer Exception]]></name> + <rule key="AvoidThrowingNullPointerException"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/strictexception.xml/AvoidThrowingNullPointerException]]></configKey> - - <description> - <![CDATA[Avoid throwing a NullPointerException - it's confusing because most people will assume that the virtual machine threw it. Consider using an IllegalArgumentException instead; this will be clearly seen as a programmer-initiated exception.]]></description> + + </rule> - <rule key="AvoidRethrowingException" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Rethrowing Exception]]></name> + <rule key="AvoidRethrowingException"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/strictexception.xml/AvoidRethrowingException]]></configKey> - - <description><![CDATA[Catch blocks that merely rethrow a caught exception only add to code size and runtime complexity.]]></description> + + </rule> - <rule key="BeanMembersShouldSerialize" > -<priority>MAJOR</priority> - <name><![CDATA[Bean Members Should Serialize]]></name> + <rule key="BeanMembersShouldSerialize"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/javabeans.xml/BeanMembersShouldSerialize]]></configKey> - - <description> - <![CDATA[If a class is a bean, or is referenced by a bean directly or indirectly it needs to be serializable. Member variables need to be marked as transient, static, or have accessor methods in the class. Marking variables as transient is the safest and easiest modification. Accessor methods should follow the Java naming conventions, i.e.if you have a variable foo, you should provide getFoo and setFoo methods.]]></description> + + <param key="prefix" type="s"> - <description><![CDATA[A variable prefix to skip, i.e., m_]]></description> + </param> </rule> - <rule key="MissingSerialVersionUID" > -<priority>MAJOR</priority> - <name><![CDATA[Missing Serial Version UID]]></name> + <rule key="MissingSerialVersionUID"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/javabeans.xml/MissingSerialVersionUID]]></configKey> - - <description><![CDATA[Classes that are serializable should provide a serialVersionUID field. ]]></description> + + </rule> - <rule key="CloneMethodMustImplementCloneable" > -<priority>MAJOR</priority> - <name><![CDATA[Clone method must implement Cloneable]]></name> + <rule key="CloneMethodMustImplementCloneable"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/clone.xml/CloneMethodMustImplementCloneable]]></configKey> - - <description> - <![CDATA[The method clone() should only be implemented if the class implements the Cloneable interface with the exception of a final method that only throws CloneNotSupportedException. This version uses PMD's type resolution facilities, and can detect if the class implements or extends a Cloneable class ]]></description> + + </rule> - <rule key="AvoidDuplicateLiterals" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Duplicate Literals]]></name> + <rule key="AvoidDuplicateLiterals"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/strings.xml/AvoidDuplicateLiterals]]></configKey> - - <description><![CDATA[Code containing duplicate String literals can usually be improved by declaring the String as a constant field. Example : -<pre> -public class Foo { - private void bar() { - buz("Howdy"); - buz("Howdy"); - buz("Howdy"); - buz("Howdy"); - } - private void buz(String x) {} -} -</pre>]]></description> + + <param key="threshold" type="i"> - <description><![CDATA[The number of duplicate literals reporting threshold. Default is 4.]]></description> + </param> <param key="skipAnnotations" type="b"> - <description><![CDATA[Skip literals within Annotations. Default is false.]]></description> + </param> <param key="exceptionlist" type="s"> - <description><![CDATA[Strings in that list are skipped.]]></description> + </param> <param key="separator" type="s"> - <description><![CDATA[Separator used in the exceptionlist. Default is ,]]></description> + </param> <param key="exceptionfile" type="s"> - <description><![CDATA[File containing strings to skip (one string per line), only used if exceptionlist is not set.]]></description> + </param> </rule> - <rule key="StringInstantiation" > -<priority>MAJOR</priority> - <name><![CDATA[String Instantiation]]></name> + <rule key="StringInstantiation"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/strings.xml/StringInstantiation]]></configKey> - <description><![CDATA[Avoid instantiating String objects; this is usually unnecessary.]]></description> + </rule> - <rule key="StringToString" > -<priority>MAJOR</priority> - <name><![CDATA[String To String]]></name> + <rule key="StringToString"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/strings.xml/StringToString]]></configKey> - - <description><![CDATA[Avoid calling toString() on String objects; this is unnecessary.]]></description> + + </rule> - <rule key="InefficientStringBuffering" > -<priority>MAJOR</priority> - <name><![CDATA[Inefficient String Buffering]]></name> + <rule key="InefficientStringBuffering"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/strings.xml/InefficientStringBuffering]]></configKey> - <description><![CDATA[Avoid concatenating non literals in a StringBuffer constructor or append().]]></description> + </rule> - <rule key="UnnecessaryCaseChange" > -<priority>MINOR</priority> - <name><![CDATA[Unnecessary Case Change]]></name> + <rule key="UnnecessaryCaseChange"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/strings.xml/UnnecessaryCaseChange]]></configKey> - <description><![CDATA[Using equalsIgnoreCase() is faster than using toUpperCase/toLowerCase().equals()]]></description> + </rule> - <rule key="UseStringBufferLength" > -<priority>MINOR</priority> - <name><![CDATA[Use String Buffer Length]]></name> + <rule key="UseStringBufferLength"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/strings.xml/UseStringBufferLength]]></configKey> - <description> - <![CDATA[Use StringBuffer.length() to determine StringBuffer length rather than using StringBuffer.toString().equals() or StringBuffer.toString().length() ==.]]></description> + </rule> - <rule key="AppendCharacterWithChar" > -<priority>MINOR</priority> - <name><![CDATA[Append Character With Char]]></name> + <rule key="AppendCharacterWithChar"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/strings.xml/AppendCharacterWithChar]]></configKey> - <description><![CDATA[Avoid concatenating characters as strings in StringBuffer.append.]]></description> + </rule> - <rule key="ConsecutiveLiteralAppends" > -<priority>MINOR</priority> - <name><![CDATA[Consecutive Literal Appends]]></name> + <rule key="ConsecutiveLiteralAppends"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/strings.xml/ConsecutiveLiteralAppends]]></configKey> - <description><![CDATA[Consecutively calling StringBuffer.append with String literals]]></description> + <param key="threshold" type="i"> - <description><![CDATA[The report threshold. Default is 1.]]></description> + </param> </rule> - <rule key="UseIndexOfChar" > -<priority>MAJOR</priority> - <name><![CDATA[Use Index Of Char]]></name> + <rule key="UseIndexOfChar"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/strings.xml/UseIndexOfChar]]></configKey> - <description><![CDATA[Use String.indexOf(char) when checking for the index of a single character; it executes faster.]]></description> + </rule> - <rule key="InefficientEmptyStringCheck" > -<priority>MAJOR</priority> - <name><![CDATA[Inefficient Empty String Check]]></name> + <rule key="InefficientEmptyStringCheck"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/strings.xml/InefficientEmptyStringCheck]]></configKey> - <description> - <![CDATA[String.trim().length() is an inefficient way to check if a String is really empty, as it creates a new String object just to check its size. Consider creating a static function that loops through a string, checking Character.isWhitespace() on each character and returning false if a non-whitespace character is found.]]></description> + </rule> - <rule key="InsufficientStringBufferDeclaration" > -<priority>MAJOR</priority> - <name><![CDATA[Insufficient String Buffer Declaration]]></name> + <rule key="InsufficientStringBufferDeclaration"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/strings.xml/InsufficientStringBufferDeclaration]]></configKey> - <description> - <![CDATA[Failing to pre-size a StringBuffer properly could cause it to re-size many times during runtime. This rule checks the characters that are actually passed into StringBuffer.append(), but represents a best guess worst case scenario. An empty StringBuffer constructor initializes the object to 16 characters. This default is assumed if the length of the constructor can not be determined.]]></description> + </rule> - <rule key="UselessStringValueOf" > -<priority>MINOR</priority> - <name><![CDATA[Useless String Value Of]]></name> + <rule key="UselessStringValueOf"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/strings.xml/UselessStringValueOf]]></configKey> - <description><![CDATA[No need to call String.valueOf to append to a string; just use the valueOf() argument directly.]]></description> + </rule> - <rule key="StringBufferInstantiationWithChar" > -<priority>MAJOR</priority> - <name><![CDATA[String Buffer Instantiation With Char]]></name> + <rule key="StringBufferInstantiationWithChar"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/strings.xml/StringBufferInstantiationWithChar]]></configKey> - - <description><![CDATA[StringBuffer sb = new StringBuffer('c'); The char will be converted into int to intialize StringBuffer size. ]]></description> + + </rule> - <rule key="ExcessiveMethodLength" > -<priority>MAJOR</priority> - <name><![CDATA[Excessive Method Length]]></name> + <rule key="ExcessiveMethodLength"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/codesize.xml/ExcessiveMethodLength]]></configKey> - - <description> - <![CDATA[Violations of this rule usually indicate that the method is doing too much. Try to reduce the method size by creating helper methods and removing any copy/pasted code.]]></description> + + <param key="minimum" type="i"> - <description><![CDATA[The method size reporting threshold. Default is 100.]]></description> + </param> </rule> - <rule key="ExcessiveParameterList" > -<priority>MAJOR</priority> - <name><![CDATA[Excessive Parameter List]]></name> + <rule key="ExcessiveParameterList"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/codesize.xml/ExcessiveParameterList]]></configKey> - - <description> - <![CDATA[Long parameter lists can indicate that a new object should be created to wrap the numerous parameters. Basically, try to group the parameters together.]]></description> + + <param key="minimum" type="i"> - <description><![CDATA[The parameter count reporting threshold. Default is 10.]]></description> + </param> </rule> - <rule key="ExcessiveClassLength" > -<priority>MAJOR</priority> - <name><![CDATA[Excessive Class Length]]></name> + <rule key="ExcessiveClassLength"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/codesize.xml/ExcessiveClassLength]]></configKey> - - <description> - <![CDATA[Long Class files are indications that the class may be trying to do too much. Try to break it down, and reduce the size to something manageable.]]></description> + + <param key="minimum" type="i"> - <description><![CDATA[The class size reporting threshold. Default is 1000.]]></description> + </param> </rule> - <rule key="ExcessivePublicCount" > -<priority>MAJOR</priority> - <name><![CDATA[Excessive Public Count]]></name> + <rule key="ExcessivePublicCount"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/codesize.xml/ExcessivePublicCount]]></configKey> - - <description> - <![CDATA[A large number of public methods and attributes declared in a class can indicate the class may need to be broken up as increased effort will be required to thoroughly test it.]]></description> + + <param key="minimum" type="i"> - <description><![CDATA[The public item reporting threshold. Default is 45.]]></description> + </param> </rule> - <rule key="TooManyFields" > -<priority>MAJOR</priority> - <name><![CDATA[Too Many Fields]]></name> + <rule key="TooManyFields"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/codesize.xml/TooManyFields]]></configKey> - - <description> - <![CDATA[Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.]]></description> + + <param key="maxfields" type="i"> - <description><![CDATA[The field count reporting threshold. Default is 15.]]></description> + </param> </rule> - <rule key="NcssMethodCount" > -<priority>MAJOR</priority> - <name><![CDATA[Ncss Method Count]]></name> + <rule key="NcssMethodCount"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/codesize.xml/NcssMethodCount]]></configKey> - - <description> - <![CDATA[This rule uses the NCSS (Non Commenting Source Statements) algorithm to determine the number of lines of code for a given method. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one.]]></description> + + <param key="minimum" type="i"> - <description><![CDATA[The method NCSS count reporting threshold. Default is 100.]]></description> + </param> </rule> - <rule key="NcssTypeCount" > -<priority>MAJOR</priority> - <name><![CDATA[Ncss Type Count]]></name> + <rule key="NcssTypeCount"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/codesize.xml/NcssTypeCount]]></configKey> - - <description> - <![CDATA[This rule uses the NCSS (Non Commenting Source Statements) algorithm to determine the number of lines of code for a given type. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one.]]></description> + + <param key="minimum" type="i"> - <description><![CDATA[The type NCSS count reporting threshold. Default is 1500.]]></description> + </param> </rule> - <rule key="NcssConstructorCount" > -<priority>MAJOR</priority> - <name><![CDATA[Ncss Constructor Count]]></name> + <rule key="NcssConstructorCount"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/codesize.xml/NcssConstructorCount]]></configKey> - - <description> - <![CDATA[This rule uses the NCSS (Non Commenting Source Statements) algorithm to determine the number of lines of code for a given constructor. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one.]]></description> + + <param key="minimum" type="i"> - <description><![CDATA[The constructor NCSS count reporting threshold. Default is 100.]]></description> + </param> </rule> - <rule key="DuplicateImports" > -<priority>MINOR</priority> - <name><![CDATA[Duplicate Imports]]></name> + <rule key="DuplicateImports"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/imports.xml/DuplicateImports]]></configKey> - - <description><![CDATA[Avoid duplicate import statements.]]></description> + + </rule> - <rule key="DontImportJavaLang" > -<priority>MINOR</priority> - <name><![CDATA[Dont Import Java Lang]]></name> + <rule key="DontImportJavaLang"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/imports.xml/DontImportJavaLang]]></configKey> - - <description><![CDATA[Avoid importing anything from the package 'java.lang'. These classes are automatically imported (JLS 7.5.3).]]></description> + + </rule> - <rule key="ImportFromSamePackage" > -<priority>MINOR</priority> - <name><![CDATA[Import From Same Package]]></name> + <rule key="ImportFromSamePackage"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/imports.xml/ImportFromSamePackage]]></configKey> - - <description><![CDATA[No need to import a type that lives in the same package.]]></description> + + </rule> - <rule key="CloneThrowsCloneNotSupportedException" > -<priority>MAJOR</priority> - <name><![CDATA[Clone Throws Clone Not Supported Exception]]></name> + <rule key="CloneThrowsCloneNotSupportedException"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/clone.xml/CloneThrowsCloneNotSupportedException]]></configKey> - - <description><![CDATA[The method clone() should throw a CloneNotSupportedException.]]></description> + + </rule> - <rule key="UseCorrectExceptionLogging" > -<priority>MAJOR</priority> - <name><![CDATA[Use Correct Exception Logging]]></name> + <rule key="UseCorrectExceptionLogging"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging]]></configKey> - - <description><![CDATA[To make sure the full stacktrace is printed out, use the logging statement with 2 arguments: a String and a Throwable.]]></description> + + </rule> - <rule key="ProperLogger" > -<priority>MAJOR</priority> - <name><![CDATA[Proper Logger]]></name> + <rule key="ProperLogger"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/logging-jakarta-commons.xml/ProperLogger]]></configKey> - - <description> - <![CDATA[Logger should normally be defined private static final and have the correct class. Private final Log log; is also allowed for rare cases when loggers need to be passed around, but the logger needs to be passed into the constructor. ]]></description> + + <param key="staticLoggerName" type="s"> - <description><![CDATA[Default is LOG]]></description> + </param> </rule> - <rule key="ShortVariable" > -<priority>MAJOR</priority> - <name><![CDATA[Short Variable]]></name> + <rule key="ShortVariable"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/naming.xml/ShortVariable]]></configKey> - - <description><![CDATA[Detects when a field, local, or parameter has a very short name.]]></description> + + </rule> - <rule key="LongVariable" > -<priority>MAJOR</priority> - <name><![CDATA[Long Variable]]></name> + <rule key="LongVariable"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/naming.xml/LongVariable]]></configKey> - - <description><![CDATA[Detects when a field, formal or local variable is declared with a long name.]]></description> + + <param key="minimum" type="i"> - <description><![CDATA[The variable length reporting threshold. Default is 17.]]></description> + </param> </rule> - <rule key="ShortMethodName" > -<priority>MAJOR</priority> - <name><![CDATA[Naming - Short method name]]></name> + <rule key="ShortMethodName"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/naming.xml/ShortMethodName]]></configKey> - - <description><![CDATA[Detects when very short method names are used. Example : -<pre> -public class ShortMethod { - public void a( int i ) { // Violation - } -} -</pre>]]></description> - </rule> - <rule key="VariableNamingConventions" > -<priority>MAJOR</priority> - <name><![CDATA[Naming - Variable naming conventions]]></name> + + + </rule> + <rule key="VariableNamingConventions"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/naming.xml/VariableNamingConventions]]></configKey> - - <description> - <![CDATA[A variable naming conventions rule - customize this to your liking. Currently, it checks for final variables that should be fully capitalized and non-final variables that should not include underscores.]]></description> + + <param key="staticPrefix" type="s"> - <description><![CDATA[A prefix for static variables]]></description> + </param> <param key="staticSuffix" type="s"> - <description><![CDATA[A suffix for static variables]]></description> + </param> <param key="memberPrefix" type="s"> - <description><![CDATA[A prefix for member variables]]></description> + </param> <param key="memberSuffix" type="s"> - <description><![CDATA[A suffix for member variables]]></description> + </param> </rule> - <rule key="MethodNamingConventions" > -<priority>MAJOR</priority> - <name><![CDATA[Naming - Method naming conventions]]></name> + <rule key="MethodNamingConventions"> + <priority>MAJOR</priority> + <configKey>rulesets/naming.xml/MethodNamingConventions</configKey> - - <description> - <![CDATA[Method names should always begin with a lower case character, and should not contain underscores. Example : -<pre> -public class Foo { - public void fooStuff() { - } -}]]></description> - </rule> - <rule key="ClassNamingConventions" > -<priority>MAJOR</priority> - <name><![CDATA[Naming - Class naming conventions]]></name> + + + </rule> + <rule key="ClassNamingConventions"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/naming.xml/ClassNamingConventions]]></configKey> - - <description><![CDATA[Class names should always begin with an upper case character.]]></description> + + </rule> - <rule key="AvoidDollarSigns" > -<priority>MINOR</priority> - <name><![CDATA[Naming - Avoid dollar signs]]></name> + <rule key="AvoidDollarSigns"> + <priority>MINOR</priority> + <configKey><![CDATA[rulesets/naming.xml/AvoidDollarSigns]]></configKey> - - <description><![CDATA[Avoid using dollar signs in variable/method/class/interface names.]]></description> + + </rule> - <rule key="MethodWithSameNameAsEnclosingClass" > -<priority>MAJOR</priority> - <name><![CDATA[Naming - Method with same name as enclosing class]]></name> + <rule key="MethodWithSameNameAsEnclosingClass"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/naming.xml/MethodWithSameNameAsEnclosingClass]]></configKey> - - <description><![CDATA[Non-constructor methods should not have the same name as the enclosing class. Example : -<pre> -public class MyClass { - // this is bad because it is a method - public void MyClass() {} - // this is OK because it is a constructor - public MyClass() {} -} -</pre>]]></description> - </rule> - <rule key="SuspiciousHashcodeMethodName" > -<priority>MAJOR</priority> - <name><![CDATA[Naming - Suspicious Hashcode method name]]></name> + + + </rule> + <rule key="SuspiciousHashcodeMethodName"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/naming.xml/SuspiciousHashcodeMethodName]]></configKey> - - <description><![CDATA[The method name and return type are suspiciously close to hashCode(), which may mean you are intending to override the hashCode() method. Example : -<pre> -public class Foo { - public int hashcode() { - // oops, this probably was supposed to be hashCode - } -}</pre>]]></description> - </rule> - <rule key="SuspiciousConstantFieldName" > -<priority>MAJOR</priority> - <name><![CDATA[Naming - Suspicious constant field name]]></name> + + + </rule> + <rule key="SuspiciousConstantFieldName"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/naming.xml/SuspiciousConstantFieldName]]></configKey> - - <description><![CDATA[A field name is all in uppercase characters, which in Sun's Java naming conventions indicate a constant. However, the field is not final. Example : -<pre> -public class Foo { - // this is bad, since someone could accidentally - // do PI = 2.71828; which is actualy e - // final double PI = 3.16; is ok - double PI = 3.16; -} -</pre>]]></description> - </rule> - <rule key="SuspiciousEqualsMethodName" > -<priority>CRITICAL</priority> - <name><![CDATA[Naming - Suspicious equals method name]]></name> + + + </rule> + <rule key="SuspiciousEqualsMethodName"> + <priority>CRITICAL</priority> + <configKey><![CDATA[rulesets/naming.xml/SuspiciousEqualsMethodName]]></configKey> - - <description> - <![CDATA[The method name and parameter number are suspiciously close to equals(Object), which may mean you are intending to override the equals(Object) method. Example : -<pre> -public class Foo { - public int equals(Object o) { - // oops, this probably was supposed to be boolean equals - } - public boolean equals(String s) { - // oops, this probably was supposed to be equals(Object) - } -} -</pre>]]></description> - </rule> - <rule key="AvoidFieldNameMatchingTypeName" > -<priority>MAJOR</priority> - <name><![CDATA[Naming - Avoid field name matching type name]]></name> + + + </rule> + <rule key="AvoidFieldNameMatchingTypeName"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/naming.xml/AvoidFieldNameMatchingTypeName]]></configKey> - - <description> - <![CDATA[It is somewhat confusing to have a field name matching the declaring class name. This probably means that type and or field names could be more precise. Example : -<pre> -public class Foo extends Bar { - // There's probably a better name for foo - int foo; -} -</pre>]]></description> - </rule> - <rule key="AvoidFieldNameMatchingMethodName" > -<priority>MAJOR</priority> - <name><![CDATA[Naming - Avoid field name matching method name]]></name> + + + </rule> + <rule key="AvoidFieldNameMatchingMethodName"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/naming.xml/AvoidFieldNameMatchingMethodName]]></configKey> - - <description> - <![CDATA[It is somewhat confusing to have a field name with the same name as a method. While this is totally legal, having information (field) and actions (method) is not clear naming. Example : -<pre> -public class Foo { - Object bar; - // bar is data or an action or both? - void bar() { - } -} -</pre>]]></description> - </rule> - <rule key="MisleadingVariableName" > -<priority>MAJOR</priority> - <name><![CDATA[Naming - Misleading variable name]]></name> + + + </rule> + <rule key="MisleadingVariableName"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/naming.xml/MisleadingVariableName]]></configKey> - - <description><![CDATA[Detects when a non-field has a name starting with 'm_'. This usually indicates a field and thus is confusing. Example : -<pre> -public class Foo { - private int m_foo; // OK - public void bar(String m_baz) { // Bad - int m_boz = 42; // Bad - } -} -</pre>]]></description> - </rule> - <rule key="ReplaceVectorWithList" > -<priority>MAJOR</priority> - <name><![CDATA[Replace Vector With List]]></name> + + + </rule> + <rule key="ReplaceVectorWithList"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/migrating.xml/ReplaceVectorWithList]]></configKey> - <description><![CDATA[Consider replacing Vector usages with the newer java.util.ArrayList if expensive threadsafe operation is not required.]]></description> + </rule> - <rule key="ReplaceHashtableWithMap" > -<priority>MAJOR</priority> - <name><![CDATA[Replace Hashtable With Map]]></name> + <rule key="ReplaceHashtableWithMap"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/migrating.xml/ReplaceHashtableWithMap]]></configKey> - <description><![CDATA[Consider replacing this Hashtable with the newer java.util.Map]]></description> + </rule> - <rule key="ReplaceEnumerationWithIterator" > -<priority>MAJOR</priority> - <name><![CDATA[Replace Enumeration With Iterator]]></name> + <rule key="ReplaceEnumerationWithIterator"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/migrating.xml/ReplaceEnumerationWithIterator]]></configKey> - <description><![CDATA[Consider replacing this Enumeration with the newer java.util.Iterator]]></description> + </rule> - <rule key="AvoidEnumAsIdentifier" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Enum As Identifier]]></name> + <rule key="AvoidEnumAsIdentifier"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/migrating.xml/AvoidEnumAsIdentifier]]></configKey> - <description><![CDATA[Finds all places 'enum' is used as an identifier is used.]]></description> + </rule> - <rule key="AvoidAssertAsIdentifier" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Assert As Identifier]]></name> + <rule key="AvoidAssertAsIdentifier"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/migrating.xml/AvoidAssertAsIdentifier]]></configKey> - <description><![CDATA[Finds all places 'assert' is used as an identifier is used.]]></description> + </rule> - <rule key="IntegerInstantiation" > -<priority>MAJOR</priority> - <name><![CDATA[Integer Instantiation]]></name> + <rule key="IntegerInstantiation"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/migrating.xml/IntegerInstantiation]]></configKey> - <description><![CDATA[In JDK 1.5, calling new Integer() causes memory allocation. Integer.valueOf() is more memory friendly.]]></description> + </rule> - <rule key="MoreThanOneLogger" > -<priority>MAJOR</priority> - <name><![CDATA[More Than One Logger]]></name> + <rule key="MoreThanOneLogger"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/logging-java.xml/MoreThanOneLogger]]></configKey> - - <description><![CDATA[Normally only one logger is used in each class.]]></description> + + </rule> - <rule key="LoggerIsNotStaticFinal" > -<priority>MAJOR</priority> - <name><![CDATA[Logger Is Not Static Final]]></name> + <rule key="LoggerIsNotStaticFinal"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/logging-java.xml/LoggerIsNotStaticFinal]]></configKey> - <description><![CDATA[In most cases, the Logger can be declared static and final.]]></description> + </rule> - <rule key="SystemPrintln" > -<priority>MAJOR</priority> - <name><![CDATA[System Println]]></name> + <rule key="SystemPrintln"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/logging-java.xml/SystemPrintln]]></configKey> - - <description><![CDATA[System.(out|err).print is used, consider using a logger.]]></description> + + </rule> - <rule key="AvoidPrintStackTrace" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Print Stack Trace]]></name> + <rule key="AvoidPrintStackTrace"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/logging-java.xml/AvoidPrintStackTrace]]></configKey> - - <description><![CDATA[Avoid printStackTrace(); use a logger call instead.]]></description> + + </rule> - <rule key="IfStmtsMustUseBraces" > -<priority>MAJOR</priority> - <name><![CDATA[If Stmts Must Use Braces]]></name> + <rule key="IfStmtsMustUseBraces"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/braces.xml/IfStmtsMustUseBraces]]></configKey> - - <description><![CDATA[Avoid using if statements without using curly braces.]]></description> + + </rule> - <rule key="WhileLoopsMustUseBraces" > -<priority>MAJOR</priority> - <name><![CDATA[While Loops Must Use Braces]]></name> + <rule key="WhileLoopsMustUseBraces"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/braces.xml/WhileLoopsMustUseBraces]]></configKey> - - <description><![CDATA[Avoid using 'while' statements without using curly braces.]]></description> + + </rule> - <rule key="IfElseStmtsMustUseBraces" > -<priority>MAJOR</priority> - <name><![CDATA[If Else Stmts Must Use Braces]]></name> + <rule key="IfElseStmtsMustUseBraces"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/braces.xml/IfElseStmtsMustUseBraces]]></configKey> - - <description><![CDATA[Avoid using if..else statements without using curly braces.]]></description> + + </rule> - <rule key="ForLoopsMustUseBraces" > -<priority>MAJOR</priority> - <name><![CDATA[For Loops Must Use Braces]]></name> + <rule key="ForLoopsMustUseBraces"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/braces.xml/ForLoopsMustUseBraces]]></configKey> - - <description><![CDATA[Avoid using 'for' statements without using curly braces, like <code>for (int i=0; i<42;i++) foo();</code>]]></description> + + </rule> - <rule key="AvoidUsingHardCodedIP" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Using Hard Coded IP]]></name> + <rule key="AvoidUsingHardCodedIP"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic.xml/AvoidUsingHardCodedIP]]></configKey> - - <description><![CDATA[An application with hard coded IP may become impossible to deploy in some case. It never hurts to externalize IP adresses.]]></description> + + <param key="pattern" type="r"> - <description><![CDATA[Regular Expression. Default is ^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$]]></description> + </param> </rule> - <rule key="CheckResultSet" > -<priority>MAJOR</priority> - <name><![CDATA[Check ResultSet]]></name> + <rule key="CheckResultSet"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/basic.xml/CheckResultSet]]></configKey> - - <description> - <![CDATA[Always check the return of one of the navigation method (next,previous,first,last) of a ResultSet. Indeed, if the value return is "false", the developer should deal with it !]]></description> + + </rule> - <rule key="AvoidUsingShortType" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Using Short Type]]></name> + <rule key="AvoidUsingShortType"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/controversial.xml/AvoidUsingShortType]]></configKey> - <description> - <![CDATA[Java uses the short type to reduce memory usage, not to optimize calculation. On the contrary, the jvm does not has an arithmetic capabilities with the type short. So, the P-code must convert the short into int, then do the proper caculation and then again, convert int to short. So, use of the "short" type may have a great effect on memory usage.]]></description> + </rule> - <rule key="AvoidUsingVolatile" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Using Volatile]]></name> + <rule key="AvoidUsingVolatile"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/controversial.xml/AvoidUsingVolatile]]></configKey> - - <description> - <![CDATA[Use of the keyword "volatile" is general used to fine tune a Java application, and therefore, requires a good expertise of the Java Memory Model. Morover, its range of action is somewhat misknown. Therefore, the volatile keyword should not be used for maintenance purpose and portability.]]></description> + + </rule> - <rule key="AvoidUsingNativeCode" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Using Native Code]]></name> + <rule key="AvoidUsingNativeCode"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/controversial.xml/AvoidUsingNativeCode]]></configKey> - <description> - <![CDATA[As JVM and Java language offer already many help in creating application, it should be very rare to have to rely on non-java code. Even though, it is rare to actually have to use Java Native Interface (JNI). As the use of JNI make application less portable, and harder to maintain, it is not recommended.]]></description> + </rule> - <rule key="AvoidAccessibilityAlteration" > -<priority>MAJOR</priority> - <name><![CDATA[Avoid Accessibility Alteration]]></name> + <rule key="AvoidAccessibilityAlteration"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/controversial.xml/AvoidAccessibilityAlteration]]></configKey> - - <description> - <![CDATA[Methods such as getDeclaredConstructors(), getDeclaredConstructor(Class[]) and setAccessible(), as the interface PrivilegedAction, allow to alter, at runtime, the visilibilty of variable, classes, or methods, even if they are private. Obviously, no one should do so, as such behavior is against everything encapsulation principal stands for.]]></description> + + </rule> - <rule key="EmptyMethodInAbstractClassShouldBeAbstract" > -<priority>MAJOR</priority> - <name><![CDATA[Empty Method In Abstract Class Should Be Abstract]]></name> + <rule key="EmptyMethodInAbstractClassShouldBeAbstract"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/design.xml/EmptyMethodInAbstractClassShouldBeAbstract]]></configKey> - - <description> - <![CDATA[An empty method in an abstract class should be abstract instead, as developer may rely on this empty implementation rather than code the appropriate one. - <pre> -public abstract class ShouldBeAbstract -{ - public Object couldBeAbstract() - { - // Should be abstract method ? - return null; - } - - public void couldBeAbstract() - { - } -} -</pre>]]></description> - </rule> - <rule key="TooManyStaticImports" > -<priority>MAJOR</priority> - <name><![CDATA[Too Many Static Imports]]></name> + + + </rule> + <rule key="TooManyStaticImports"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/imports.xml/TooManyStaticImports]]></configKey> - - <description> - <![CDATA[If you overuse the static import feature, it can make your program unreadable and unmaintainable, polluting its namespace with all the static members you import. Readers of your code (including you, a few months after you wrote it) will not know which class a static member comes from (Sun 1.5 Language Guide).]]></description> + + <param key="maximumStaticImports" type="i"> - <description><![CDATA[All static imports can be disallowed by setting this to 0. Default is 4.]]></description> + </param> </rule> - <rule key="DoNotCallSystemExit" > -<priority>MAJOR</priority> - <name><![CDATA[Do Not Call System Exit]]></name> + <rule key="DoNotCallSystemExit"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/j2ee.xml/DoNotCallSystemExit]]></configKey> - - <description><![CDATA[Web applications should not call System.exit(), since only the web container or the application server should stop the JVM.]]></description> + + </rule> - <rule key="StaticEJBFieldShouldBeFinal" > -<priority>MAJOR</priority> - <name><![CDATA[Static EJB Field Should Be Final]]></name> + <rule key="StaticEJBFieldShouldBeFinal"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/j2ee.xml/StaticEJBFieldShouldBeFinal]]></configKey> - - <description> - <![CDATA[According to the J2EE specification (p.494), an EJB should not have any static fields with write access. However, static read only fields are allowed. This ensures proper behavior especially when instances are distributed by the container on several JREs.]]></description> + + </rule> - <rule key="DoNotUseThreads" > -<priority>MAJOR</priority> - <name><![CDATA[Do Not Use Threads]]></name> + <rule key="DoNotUseThreads"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/j2ee.xml/DoNotUseThreads]]></configKey> - - <description><![CDATA[The J2EE specification explicitly forbid use of threads.]]></description> + + </rule> - <rule key="MDBAndSessionBeanNamingConvention" > -<priority>MAJOR</priority> - <name><![CDATA[Message Driven Bean And Session Bean Naming Convention]]></name> + <rule key="MDBAndSessionBeanNamingConvention"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/j2ee.xml/MDBAndSessionBeanNamingConvention]]></configKey> - - <description><![CDATA[The EJB Specification state that any MessageDrivenBean or SessionBean should be suffixed by Bean.]]></description> + + </rule> - <rule key="RemoteSessionInterfaceNamingConvention" > -<priority>MAJOR</priority> - <name><![CDATA[Remote Session Interface Naming Convention]]></name> + <rule key="RemoteSessionInterfaceNamingConvention"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/j2ee.xml/RemoteSessionInterfaceNamingConvention]]></configKey> - - <description><![CDATA[Remote Home interface of a Session EJB should be suffixed by "Home".]]></description> + + </rule> - <rule key="LocalInterfaceSessionNamingConvention" > -<priority>MAJOR</priority> - <name><![CDATA[Local Interface Session Naming Convention]]></name> + <rule key="LocalInterfaceSessionNamingConvention"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/j2ee.xml/LocalInterfaceSessionNamingConvention]]></configKey> - - <description><![CDATA[The Local Interface of a Session EJB should be suffixed by "Local".]]></description> + + </rule> - <rule key="LocalHomeNamingConvention" > -<priority>MAJOR</priority> - <name><![CDATA[Local Home Naming Convention]]></name> + <rule key="LocalHomeNamingConvention"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/j2ee.xml/LocalHomeNamingConvention]]></configKey> - - <description><![CDATA[The Local Home interface of a Session EJB should be suffixed by "LocalHome".]]></description> + + </rule> - <rule key="RemoteInterfaceNamingConvention" > -<priority>MAJOR</priority> - <name><![CDATA[Remote Interface Naming Convention]]></name> + <rule key="RemoteInterfaceNamingConvention"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/j2ee.xml/RemoteInterfaceNamingConvention]]></configKey> - - <description><![CDATA[Remote Interface of a Session EJB should NOT be suffixed.]]></description> + + </rule> - <rule key="UseEqualsToCompareStrings" > -<priority>MAJOR</priority> - <name><![CDATA[Use Equals To Compare Strings]]></name> + <rule key="UseEqualsToCompareStrings"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/strings.xml/UseEqualsToCompareStrings]]></configKey> - - <description><![CDATA[Using "==" or "!=" to compare strings only works if intern version is used on both sides.]]></description> + + </rule> - <rule key="DoNotExtendJavaLangError" > -<priority>MAJOR</priority> - <name><![CDATA[Do Not Extend Java Lang Error]]></name> + <rule key="DoNotExtendJavaLangError"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/strictexception.xml/DoNotExtendJavaLangError]]></configKey> - - <description><![CDATA[Errors are system exceptions. Do not extend them.]]></description> + + </rule> - <rule key="AddEmptyString" > -<priority>MAJOR</priority> - <name><![CDATA[Add Empty String]]></name> + <rule key="AddEmptyString"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/optimizations.xml/AddEmptyString]]></configKey> - <description><![CDATA[Finds empty string literals which are being added. This is an inefficient way to convert any type to a String.]]></description> + </rule> - <rule key="BooleanGetMethodName" > -<priority>MAJOR</priority> - <name><![CDATA[Boolean Get Method Name]]></name> + <rule key="BooleanGetMethodName"> + <priority>MAJOR</priority> + <configKey><![CDATA[rulesets/naming.xml/BooleanGetMethodName]]></configKey> - - <description><![CDATA[Looks for methods named "getX()" with "boolean" as the return type. The convention is to name these methods "isX()".]]></description> + + <param key="checkParameterizedMethods" type="b"> - <description><![CDATA[Check parameterized methods. Default is false.]]></description> + </param> </rule> - <rule key="XPathRule" > -<priority>MAJOR</priority> - <name><![CDATA[XPath rule template]]></name> + <rule key="XPathRule"> + <priority>MAJOR</priority> + <configKey><![CDATA[net.sourceforge.pmd.rules.XPathRule]]></configKey> - + <cardinality>MULTIPLE</cardinality> - <description> - <![CDATA[PMD provides a very handy method for creating new rules by writing an XPath query. When the XPath query finds a match, a violation is created. - Let's take a simple example : assume we have a Factory class that must be always declared final. - We'd like to report a violation each time a declaration of Factory is not declared final. Consider the following class: : -<pre> -public class a { - Factory f1; - - void myMethod() { - Factory f2; - int a; - } -} -</pre> - The following expression does the magic we need: -<pre> -//VariableDeclarator - [../Type/ReferenceType/ClassOrInterfaceType - [@Image = 'Factory'] and ..[@Final='false']] -</pre> - See the <a href="http://pmd.sourceforge.net/xpathruletutorial.html">XPath rule tutorial</a> for more information.]]> - </description> + <param key="xpath" type="s"> - <description><![CDATA[XPath expressions.]]></description> + </param> <param key="message" type="s"> - <description><![CDATA[Message to display when a violation occurs.]]></description> - </param> - </rule> + + </param> + </rule> </rules>
\ No newline at end of file diff --git a/sonar-core/src/main/java/org/sonar/core/i18n/I18nManager.java b/sonar-core/src/main/java/org/sonar/core/i18n/I18nManager.java index 4a8ee47f82f..65304cd44c0 100644 --- a/sonar-core/src/main/java/org/sonar/core/i18n/I18nManager.java +++ b/sonar-core/src/main/java/org/sonar/core/i18n/I18nManager.java @@ -131,6 +131,10 @@ public class I18nManager implements I18n, ServerExtension { return result; } + Set<String> getPropertyKeys() { + return propertyToBundles.keySet(); + } + ResourceBundle getBundle(String bundleKey, Locale locale) { try { ClassLoader classloader = bundleToClassloaders.get(bundleKey); diff --git a/sonar-core/src/main/java/org/sonar/core/i18n/RuleI18nManager.java b/sonar-core/src/main/java/org/sonar/core/i18n/RuleI18nManager.java index 764871806cc..6d681196c28 100644 --- a/sonar-core/src/main/java/org/sonar/core/i18n/RuleI18nManager.java +++ b/sonar-core/src/main/java/org/sonar/core/i18n/RuleI18nManager.java @@ -19,93 +19,126 @@ */ package org.sonar.core.i18n; +import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; import org.sonar.api.ServerComponent; +import java.util.List; import java.util.Locale; public class RuleI18nManager implements ServerComponent { private I18nManager i18nManager; + private RuleKey[] ruleKeys; public RuleI18nManager(I18nManager i18nManager) { this.i18nManager = i18nManager; } + public void start() { + List<RuleKey> list = Lists.newArrayList(); + for (String propertyKey : i18nManager.getPropertyKeys()) { + if (isRuleProperty(propertyKey)) { + list.add(extractRuleKey(propertyKey)); + } + } + this.ruleKeys = list.toArray(new RuleKey[list.size()]); + } + public String getName(String repositoryKey, String ruleKey, Locale locale) { - return message(repositoryKey, ruleKey, locale, ".name", ruleKey); + return message(repositoryKey, ruleKey, locale, ".name"); } public String getDescription(String repositoryKey, String ruleKey, Locale locale) { - String relatedProperty = "rule." + repositoryKey + "." + ruleKey + ".name"; + String relatedProperty = new StringBuilder().append("rule.").append(repositoryKey).append(".").append(ruleKey).append(".name").toString(); // TODO add cache String description = i18nManager.messageFromFile(locale, ruleKey + ".html", relatedProperty); if (description == null && !Locale.ENGLISH.equals(locale)) { description = i18nManager.messageFromFile(Locale.ENGLISH, ruleKey + ".html", relatedProperty); } - return StringUtils.defaultString(description, ""); + return description; } public String getParamDescription(String repositoryKey, String ruleKey, String paramKey, Locale locale) { - return message(repositoryKey, ruleKey, locale, ".param." + paramKey, ""); + return message(repositoryKey, ruleKey, locale, ".param." + paramKey); } - private String message(String repositoryKey, String ruleKey, Locale locale, String suffix, String defaultValue) { + String message(String repositoryKey, String ruleKey, Locale locale, String suffix) { String propertyKey = new StringBuilder().append("rule.").append(repositoryKey).append(".").append(ruleKey).append(suffix).toString(); - return i18nManager.message(locale, propertyKey, defaultValue); + return i18nManager.message(locale, propertyKey, null); + } + + public List<RuleKey> searchNames(String search, Locale locale) { + List<RuleKey> result = Lists.newArrayList(); + for (RuleKey ruleKey : ruleKeys) { + String name = i18nManager.message(locale, ruleKey.getNameProperty(), null); + if (name != null && StringUtils.indexOfIgnoreCase(name, search) >= 0) { + result.add(ruleKey); + } + } + return result; + } + + RuleKey[] getRuleKeys() { + return ruleKeys; } -// static class RuleKey { -// private String repositoryKey; -// private String key; -// -// RuleKey(String repositoryKey, String key) { -// this.repositoryKey = repositoryKey; -// this.key = key; -// } -// -// public String getRepositoryKey() { -// return repositoryKey; -// } -// -// public String getKey() { -// return key; -// } -// -// @Override -// public boolean equals(Object o) { -// if (this == o) return true; -// if (o == null || getClass() != o.getClass()) return false; -// -// RuleKey ruleKey = (RuleKey) o; -// -// if (!key.equals(ruleKey.key)) return false; -// if (!repositoryKey.equals(ruleKey.repositoryKey)) return false; -// -// return true; -// } -// -// @Override -// public int hashCode() { -// int result = repositoryKey.hashCode(); -// result = 31 * result + key.hashCode(); -// return result; -// } -// -// @Override -// public String toString() { -// return new StringBuilder().append(repositoryKey).append(":").append(key).toString(); -// } -// } -// -// static class RuleMessages { -// private String name; -// private String description; -// -// RuleMessages(String name, String description) { -// this.name = name; -// this.description = description; -// } -// } + static RuleKey extractRuleKey(String propertyKey) { + String s = StringUtils.substringBetween(propertyKey, "rule.", ".name"); + String ruleKey = StringUtils.substringAfter(s, "."); + String repository = StringUtils.substringBefore(s, "."); + return new RuleKey(repository, ruleKey); + } + + static boolean isRuleProperty(String propertyKey) { + return StringUtils.startsWith(propertyKey, "rule.") && StringUtils.endsWith(propertyKey, ".name") && propertyKey.indexOf(".param.") < 0; + } + + public static class RuleKey { + private String repositoryKey; + private String key; + + RuleKey(String repositoryKey, String key) { + this.repositoryKey = repositoryKey; + this.key = key; + } + + public String getRepositoryKey() { + return repositoryKey; + } + + public String getKey() { + return key; + } + + public String getNameProperty() { + return new StringBuilder().append("rule.").append(repositoryKey).append(".").append(key).append(".name").toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + RuleKey ruleKey = (RuleKey) o; + + if (!key.equals(ruleKey.key)) return false; + if (!repositoryKey.equals(ruleKey.repositoryKey)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = repositoryKey.hashCode(); + result = 31 * result + key.hashCode(); + return result; + } + + @Override + public String toString() { + return new StringBuilder().append(repositoryKey).append(":").append(key).toString(); + } + } } diff --git a/sonar-core/src/test/java/org/sonar/core/i18n/RuleI18nManagerTest.java b/sonar-core/src/test/java/org/sonar/core/i18n/RuleI18nManagerTest.java index 17608330075..448b3ade323 100644 --- a/sonar-core/src/test/java/org/sonar/core/i18n/RuleI18nManagerTest.java +++ b/sonar-core/src/test/java/org/sonar/core/i18n/RuleI18nManagerTest.java @@ -19,16 +19,18 @@ */ package org.sonar.core.i18n; +import com.google.common.collect.Sets; import org.hamcrest.core.Is; import org.junit.Test; +import java.util.Arrays; +import java.util.List; import java.util.Locale; +import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.isNotNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.junit.matchers.JUnitMatchers.hasItem; +import static org.mockito.Mockito.*; public class RuleI18nManagerTest { @Test @@ -39,7 +41,7 @@ public class RuleI18nManagerTest { ruleI18n.getName("checkstyle", "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck", Locale.ENGLISH); String propertyKey = "rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.name"; - verify(i18n).message(Locale.ENGLISH, propertyKey, "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck" /* default value is the key */); + verify(i18n).message(Locale.ENGLISH, propertyKey, null /* no default value */); verifyNoMoreInteractions(i18n); } @@ -51,7 +53,7 @@ public class RuleI18nManagerTest { ruleI18n.getParamDescription("checkstyle", "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck", "pattern", Locale.ENGLISH); String propertyKey = "rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.param.pattern"; - verify(i18n).message(Locale.ENGLISH, propertyKey, "" /* default value must be blank */); + verify(i18n).message(Locale.ENGLISH, propertyKey, null /* no default value */); verifyNoMoreInteractions(i18n); } @@ -68,11 +70,11 @@ public class RuleI18nManagerTest { } @Test - public void shoudlReturnBlankIfMissingDescription() { + public void shoudlReturnNullIfMissingDescription() { I18nManager i18n = mock(I18nManager.class); RuleI18nManager ruleI18n = new RuleI18nManager(i18n); - assertThat(ruleI18n.getDescription("checkstyle", "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck", Locale.ENGLISH), Is.is("")); + assertThat(ruleI18n.getDescription("checkstyle", "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck", Locale.ENGLISH), nullValue()); } @Test @@ -87,4 +89,88 @@ public class RuleI18nManagerTest { verify(i18n).messageFromFile(Locale.ENGLISH, "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.html", propertyKeyForName); verifyNoMoreInteractions(i18n); } + + @Test + public void shouldBeRuleKey() { + assertThat(RuleI18nManager.isRuleProperty("rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.name"), Is.is(true)); + assertThat(RuleI18nManager.isRuleProperty("rule.pmd.Header.name"), Is.is(true)); + } + + @Test + public void shouldNotBeRuleKey() { + // this is the parameter "name" + assertThat(RuleI18nManager.isRuleProperty("rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.param.name"), Is.is(false)); + assertThat(RuleI18nManager.isRuleProperty("by"), Is.is(false)); + assertThat(RuleI18nManager.isRuleProperty("something.else"), Is.is(false)); + assertThat(RuleI18nManager.isRuleProperty("checkstyle.page.name"), Is.is(false)); + } + + @Test + public void shouldExtractRuleKey() { + RuleI18nManager.RuleKey ruleKey = RuleI18nManager.extractRuleKey("rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.name"); + assertThat(ruleKey.getRepositoryKey(), Is.is("checkstyle")); + assertThat(ruleKey.getKey(), Is.is("com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck")); + assertThat(ruleKey.getNameProperty(), Is.is("rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.name")); + + ruleKey = RuleI18nManager.extractRuleKey("rule.pmd.Header.name"); + assertThat(ruleKey.getRepositoryKey(), Is.is("pmd")); + assertThat(ruleKey.getKey(), Is.is("Header")); + assertThat(ruleKey.getNameProperty(), Is.is("rule.pmd.Header.name")); + } + + @Test + public void shouldRegisterRuleKeysAtStartup() { + I18nManager i18n = mock(I18nManager.class); + when(i18n.getPropertyKeys()).thenReturn(Sets.newHashSet( + // rules + "rule.pmd.Header.name", "rule.pmd.Header.param.pattern", "rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.name", + // other + "by", "something.else")); + RuleI18nManager ruleI18n = new RuleI18nManager(i18n); + ruleI18n.start(); + + List<RuleI18nManager.RuleKey> keys = Arrays.asList(ruleI18n.getRuleKeys()); + assertThat(keys.size(), Is.is(2)); + assertThat(keys, hasItem(new RuleI18nManager.RuleKey("pmd", "Header"))); + assertThat(keys, hasItem(new RuleI18nManager.RuleKey("checkstyle", "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck"))); + } + + @Test + public void shouldSearchEnglishNames() { + I18nManager i18n = mock(I18nManager.class); + when(i18n.getPropertyKeys()).thenReturn(Sets.newHashSet("rule.pmd.Header.name", "rule.checkstyle.AnnotationUseStyleCheck.name")); + when(i18n.message(Locale.ENGLISH, "rule.pmd.Header.name", null)).thenReturn("HEADER PMD CHECK"); + when(i18n.message(Locale.ENGLISH, "rule.checkstyle.AnnotationUseStyleCheck.name", null)).thenReturn("check annotation style"); + + RuleI18nManager ruleI18n = new RuleI18nManager(i18n); + ruleI18n.start(); + + List<RuleI18nManager.RuleKey> result = ruleI18n.searchNames("ANNOTATion", Locale.ENGLISH); + assertThat(result.size(), Is.is(1)); + assertThat(result.get(0).getRepositoryKey(), Is.is("checkstyle")); + + result = ruleI18n.searchNames("bibopaloula", Locale.ENGLISH); + assertThat(result.size(), Is.is(0)); + } + + @Test + public void shouldSearchLocalizedNames() { + I18nManager i18n = mock(I18nManager.class); + when(i18n.getPropertyKeys()).thenReturn(Sets.newHashSet("rule.pmd.Header.name", "rule.checkstyle.AnnotationUseStyleCheck.name")); + when(i18n.message(Locale.ENGLISH, "rule.pmd.Header.name", null)).thenReturn("HEADER PMD CHECK"); + when(i18n.message(Locale.ENGLISH, "rule.checkstyle.AnnotationUseStyleCheck.name", null)).thenReturn("check annotation style"); + when(i18n.message(Locale.FRENCH, "rule.checkstyle.AnnotationUseStyleCheck.name", null)).thenReturn("vérifie le style des annotations"); + + RuleI18nManager ruleI18n = new RuleI18nManager(i18n); + ruleI18n.start(); + + List<RuleI18nManager.RuleKey> result = ruleI18n.searchNames("annotation", Locale.FRENCH); + assertThat(result.size(), Is.is(1)); + assertThat(result.get(0).getKey(), Is.is("AnnotationUseStyleCheck")); + + // search only in the french bundle + result = ruleI18n.searchNames("vérifie", Locale.FRENCH); + assertThat(result.size(), Is.is(1)); + assertThat(result.get(0).getKey(), Is.is("AnnotationUseStyleCheck")); + } } diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index e0ea1b1004f..df520e59ad2 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -32,6 +32,7 @@ import org.sonar.api.rules.RulePriority; import org.sonar.api.rules.RuleRepository; import org.sonar.api.utils.ValidationMessages; import org.sonar.api.web.*; +import org.sonar.core.i18n.RuleI18nManager; import org.sonar.jpa.dialect.Dialect; import org.sonar.jpa.session.DatabaseConnector; import org.sonar.markdown.Markdown; @@ -330,6 +331,13 @@ public final class JRubyFacade { return i18n.getRuleParamDescription(rubyLocale, repositoryKey, key, paramKey); } + public List<RuleI18nManager.RuleKey> searchRuleName(String rubyLocale, String searchText) { + if (i18n == null) { + i18n = getContainer().getComponent(JRubyI18n.class); + } + return i18n.searchRuleName(rubyLocale, searchText); + } + public ReviewsNotificationManager getReviewsNotificationManager() { return getContainer().getComponent(ReviewsNotificationManager.class); } diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyI18n.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyI18n.java index e7d9804e3f3..077556d67b3 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyI18n.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyI18n.java @@ -25,6 +25,7 @@ import org.sonar.api.ServerComponent; import org.sonar.api.i18n.I18n; import org.sonar.core.i18n.RuleI18nManager; +import java.util.List; import java.util.Locale; import java.util.Map; @@ -81,4 +82,8 @@ public final class JRubyI18n implements ServerComponent { public String getRuleParamDescription(String rubyLocale, String repositoryKey, String ruleKey, String paramKey) { return ruleI18nManager.getParamDescription(repositoryKey, ruleKey, paramKey, toLocale(rubyLocale)); } + + public List<RuleI18nManager.RuleKey> searchRuleName(String rubyLocale, String searchText) { + return ruleI18nManager.searchNames(searchText, toLocale(rubyLocale)); + } } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb index 6724dcbeac8..b21f4a4480e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb @@ -207,15 +207,22 @@ class Rule < ActiveRecord::Base end unless options[:searchtext].blank? - conditions << "(UPPER(rules.name) LIKE :searchtext OR plugin_rule_key = :key)" searchtext = options[:searchtext].to_s.strip + search_text_conditions='(UPPER(rules.name) LIKE :searchtext OR plugin_rule_key = :key' + + additional_keys=java_facade.searchRuleName(I18n.locale, searchtext) + additional_keys.each do |java_rule_key| + search_text_conditions<<" OR (plugin_name='#{java_rule_key.getRepositoryKey()}' AND plugin_rule_key='#{java_rule_key.getKey()}')" + end + + search_text_conditions<<')' + conditions << search_text_conditions values[:searchtext] = "%" << searchtext.clone.upcase << "%" values[:key] = searchtext end includes=(options[:include_parameters] ? :rules_parameters : nil) rules = Rule.find(:all, :include => includes, :conditions => [conditions.join(" AND "), values]).sort_by { |rule| rule.name } - filter(rules, options) end |