Index of all built-in rules available for Java
Table of Contents

Best Practices

Rules which enforce generally accepted best practices.

Code Style

Rules which enforce a specific coding style.
  • AtLeastOneConstructor: Each non-static class should declare at least one constructor. Classes with solely static members…
  • AvoidDollarSigns: Avoid using dollar signs in variable/method/class/interface names.
  • AvoidProtectedFieldInFinalClass: Do not use protected fields in final classes since they cannot be subclassed. Clarify your intent…
  • AvoidProtectedMethodInFinalClassNotExtending: Do not use protected methods in most final classes since they cannot be subclassed. This should o…
  • AvoidUsingNativeCode: Unnecessary reliance on Java Native Interface (JNI) calls directly reduces application portabilit…
  • BooleanGetMethodName: Methods that return boolean or Boolean results should be named as predicate statements to denote …
  • CallSuperInConstructor: It is a good practice to call super() in a constructor. If super() is not called but another cons…
  • ClassNamingConventions: Configurable naming conventions for type declarations. This rule reports type declara…
  • CommentDefaultAccessModifier: To avoid mistakes if we want that an Annotation, Class, Enum, Method, Constructor or Field have a…
  • ConfusingTernary: Avoid negation within an "if" expression with an "else" clause. For example, rephrase: ‘if (x !=…
  • ControlStatementBraces: Enforce a policy for braces on control statements. It is recommended to use braces on ‘if … els…
  • EmptyControlStatement: Reports control statements whose body is empty, as well as empty initializers. The ch…
  • EmptyMethodInAbstractClassShouldBeAbstract: Empty or auto-generated methods in an abstract class should be tagged as abstract. This helps to …
  • ExtendsObject: No need to explicitly extend Object.
  • FieldDeclarationsShouldBeAtStartOfClass: Fields should be declared at the top of the class, before any method declarations, constructors, …
  • FieldNamingConventions: Configurable naming conventions for field declarations. This rule reports variable declarations …
  • FinalParameterInAbstractMethod: Declaring a method parameter as final for an interface method is useless because the implementati…
  • ForLoopShouldBeWhileLoop: Some for loops can be simplified to while loops, this makes them more concise.
  • FormalParameterNamingConventions: Configurable naming conventions for formal parameters of methods and lambdas. This ru…
  • GenericsNaming: Deprecated Names for references to generic values should be limited to a single uppercase letter. Deprecated…
  • IdenticalCatchBranches: Identical ‘catch’ branches use up vertical space and increase the complexity of code without …
  • LambdaCanBeMethodReference: This rule reports lambda expressions that can be written more succinctly as a method reference. T…
  • LinguisticNaming: This rule finds Linguistic Naming Antipatterns. It checks for fields, that are named, as if they …
  • LocalHomeNamingConvention: The Local Home interface of a Session EJB should be suffixed by ‘LocalHome’.
  • LocalInterfaceSessionNamingConvention: The Local Interface of a Session EJB should be suffixed by ‘Local’.
  • LocalVariableCouldBeFinal: A local variable assigned only once can be declared final.
  • LocalVariableNamingConventions: Configurable naming conventions for local variable declarations and other locally-scoped …
  • LongVariable: Fields, formal arguments, or local variable names that are too long can make the code difficult t…
  • MDBAndSessionBeanNamingConvention: The EJB Specification states that any MessageDrivenBean or SessionBean should be suffixed by ‘Bean’.
  • MethodArgumentCouldBeFinal: Reports method and constructor parameters that can be made final because they are never reassigne…
  • MethodNamingConventions: Configurable naming conventions for method declarations. This rule reports method dec…
  • ModifierOrder: Enforces the modifier order recommended by the JLS. Apart from sorting modifiers, thi…
  • NoPackage: Detects when a class, interface, enum or annotation does not have a package definition.
  • OnlyOneReturn: A method should have only one exit point, and that should be the last statement in the method.
  • PackageCase: Detects when a package definition contains uppercase characters.
  • PrematureDeclaration: Checks for variables that are defined before they might be used. A declaration is deemed to be pr…
  • RemoteInterfaceNamingConvention: Remote Interface of a Session EJB should not have a suffix.
  • RemoteSessionInterfaceNamingConvention: A Remote Home interface type of a Session EJB should be suffixed by ‘Home’.
  • ShortClassName: Short Classnames with fewer than e.g. five characters are not recommended.
  • ShortMethodName: Method names that are very short are not helpful to the reader.
  • ShortVariable: Fields, local variables, enum constant names or parameter names that are very short are not helpf…
  • TooManyStaticImports: If you overuse the static import feature, it can make your program unreadable and unmaintainable,…
  • TypeParameterNamingConventions: Configurable naming conventions for type parameters in generic types and methods. Thi…
  • UnnecessaryAnnotationValueElement: Avoid the use of value in annotations when it’s the only element.
  • UnnecessaryBoxing: Reports explicit boxing and unboxing conversions that may safely be removed, either b…
  • UnnecessaryCast: Detects casts which could be removed as the operand of the cast is already suitable for the conte…
  • UnnecessaryConstructor: This rule detects when a constructor is not necessary; i.e., when there is only one constructor a…
  • UnnecessaryFullyQualifiedName: Import statements allow the use of non-fully qualified names. The use of a fully qualified name …
  • UnnecessaryImport: Reports import statements that can be removed. They are either unused, duplicated, or…
  • UnnecessaryInterfaceDeclaration: Implicitly declaring that a class implements an interface already implemented by its …
  • UnnecessaryLocalBeforeReturn: Deprecated Avoid the creation of unnecessary local variables. This rule has been deprecated since 7.17.0. Us…
  • UnnecessaryModifier: Fields in interfaces and annotations are automatically ‘public static final’, and methods are ‘pu…
  • UnnecessaryReturn: Avoid the use of unnecessary return statements. A return is unnecessary when no instructions foll…
  • UnnecessarySemicolon: Reports unnecessary semicolons (so called "empty statements" and "empty declarations"). …
  • UseDiamondOperator: In some cases, explicit type arguments in a constructor call for a generic type may be replaced b…
  • UseExplicitTypes: Java 10 introduced the ‘var’ keyword. This reduces the amount of code written because java can in…
  • UselessParentheses: Parenthesized expressions are used to override the default operator precedence rules….
  • UselessQualifiedThis: Reports qualified this usages in the same class.
  • UseShortArrayInitializer: When declaring and initializing array fields or variables, it is not necessary to explicitly crea…
  • UseUnderscoresInNumericLiterals: Since Java 1.7, numeric literals can use underscores to separate digits. This rule enforces that …
  • VariableCanBeInlined: Local variables should not be declared and then immediately returned or thrown. Such …

Design

Rules that help you discover design issues.
  • AbstractClassWithoutAnyMethod: If an abstract class does not provide any methods, it may be acting as a simple data container th…
  • AvoidCatchingGenericException: Deprecated The rule has been moved to another ruleset. Use instead AvoidCatchingGenericException.
  • AvoidDeeplyNestedIfStmts: Avoid creating deeply nested if-then statements since they are harder to read and error-prone to …
  • AvoidRethrowingException: Catch blocks that merely rethrow a caught exception only add to code size and runtime complexity.
  • AvoidThrowingNewInstanceOfSameException: Catch blocks that merely rethrow a caught exception wrapped inside a new instance of the same typ…
  • AvoidThrowingNullPointerException: Avoid throwing NullPointerExceptions manually. These are confusing because most people will assum…
  • AvoidThrowingRawExceptionTypes: Avoid throwing certain exception types. Rather than throw a raw RuntimeException, Throwable, Exce…
  • AvoidUncheckedExceptionsInSignatures: Reports unchecked exceptions in the ‘throws’ clause of a method or constructor. Java doesn’t forc…
  • ClassWithOnlyPrivateConstructorsShouldBeFinal: Reports classes that may be made final because they cannot be extended from outside their compila…
  • CognitiveComplexity: Methods that are highly complex are difficult to read and more costly to maintain. If you include…
  • CollapsibleIfStatements: Reports nested ‘if’ statements that can be merged together by joining their conditions with a boo…
  • CouplingBetweenObjects: This rule counts the number of unique attributes, local variables, and return types within an obj…
  • CyclomaticComplexity: The complexity of methods directly affects maintenance costs and readability. Concentrating too m…
  • DataClass: Data Classes are simple data holders, which reveal most of their state, and without complex funct…
  • DoNotExtendJavaLangError: Errors are system exceptions. Do not extend them.
  • ExceptionAsFlowControl: This rule reports exceptions thrown and caught in an enclosing try statement. This use of excepti…
  • ExcessiveImports: A high number of imports can indicate a high degree of coupling within an object. This rule count…
  • ExcessiveParameterList: Methods with numerous parameters are a challenge to maintain, especially if most of them share th…
  • ExcessivePublicCount: Classes with large numbers of public methods and attributes require disproportionate testing effo…
  • FinalFieldCouldBeStatic: If a final field is assigned to a compile-time constant, it could be made static, thus saving ove…
  • GodClass: The God Class rule detects the God Class design flaw using metrics. God classes do too many thing…
  • ImmutableField: Reports non-final fields whose value never changes once object initialization ends, and hence may…
  • InvalidJavaBean: Identifies beans, that don’t follow the [JavaBeans API specification](https://download.oracle.com…
  • LawOfDemeter: The law of Demeter is a simple rule that says "only talk to friends". It forbids fetching data fr…
  • LogicInversion: Use opposite operator instead of negating the whole expression with a logic complement operator.
  • LoosePackageCoupling: Avoid using classes from the configured package hierarchy outside of the package hierarchy, excep…
  • MutableStaticState: Non-private static fields should be made constants (or immutable references) by decla…
  • NcssCount: This rule uses the NCSS (Non-Commenting Source Statements) metric to determine the number of line…
  • NPathComplexity: The NPath complexity of a method is the number of acyclic execution paths through that method. Wh…
  • PublicMemberInNonPublicType: A non-public type should not declare its own members as public, as their visibility is effectivel…
  • SignatureDeclareThrowsException: A method/constructor shouldn’t explicitly throw the generic java.lang.Exception, since it is uncl…
  • SimplifiedTernary: Reports ternary expression with the form ‘condition ? literalBoolean : foo’ or ‘condition ? foo :…
  • SimplifyBooleanExpressions: Avoid unnecessary comparisons in boolean expressions, they serve no purpose and impacts readability.
  • SimplifyBooleanReturns: Avoid unnecessary if-then-else statements when returning a boolean. The result of the conditional…
  • SimplifyConditional: No need to check for null before an instanceof; the instanceof keyword returns false when given a…
  • SingularField: Reports fields which may be converted to a local variable. This is so because in every method whe…
  • SwitchDensity: A high ratio of statements to labels in a switch statement implies that the switch statement is o…
  • TooManyFields: Classes that have too many fields can become unwieldy and could be redesigned to have fewer field…
  • TooManyMethods: A class with too many methods is probably a good suspect for refactoring, in order to reduce its …
  • UselessOverridingMethod: The overriding method merely calls the same method defined in a superclass.
  • UseObjectForClearerAPI: When you write a public method, you should be thinking in terms of an API. If your method is publ…
  • UseUtilityClass: For classes that only have static methods, consider making them utility classes. Note that this d…

Documentation

Rules that are related to code documentation.
  • CommentContent: A rule for the politically correct… we don’t want to offend anyone.
  • CommentRequired: Denotes whether javadoc (formal) comments are required (or unwanted) for specific language elements.
  • CommentSize: Determines whether the dimensions of non-header comments found are within the specified limits.
  • DanglingJavadoc: Javadoc comments that do not belong to a class, method or field are ignored by the JavaDoc tool a…
  • UncommentedEmptyConstructor: Uncommented Empty Constructor finds instances where a constructor does not contain statements, bu…
  • UncommentedEmptyMethodBody: Uncommented Empty Method Body finds instances where a method body does not contain statements, bu…

Error Prone

Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.