Inspectopedia Help

Code style issues

'List.indexOf()' expression can be replaced with 'contains()'  

Reports any List.indexOf() expressions that can be replaced with the List.contains() method.

'Objects.equals()' can be replaced with 'equals()'  

Reports calls to Objects.equals(a, b) in which the first argument is statically known to be non-null.

'Optional' can be replaced with sequence of 'if' statements  

Reports Optional call chains that can be replaced with a sequence of if statements.

'Optional' contains array or collection  

Reports java.util.Optional or com.google.common.base.Optional types with an array or collection type parameter.

'assert' message is not a string  

Reports assert messages that are not of the java.lang.String type.

'equals()' called on enum value  

Reports equals() calls on enum constants.

'if' statement can be replaced with conditional or boolean expression  

Reports if statements that can be replaced with conditions using the &&, ||, ==, !=, or ?: operator.

'return' separated from the result computation  

Reports return statements that return a local variable where the value of the variable is computed somewhere else within the same method.

'size() == 0' can be replaced with 'isEmpty()'  

Reports .size() or .length() comparisons with a 0 literal that can be replaced with a call to .isEmpty().

'try' statement with multiple resources can be split  

Reports try statements with multiple resources that can be automatically split into multiple try-with-resources statements.

Array can be replaced with enum values  

Reports arrays of enum constants that can be replaced with a call to EnumType.values().

Array creation without 'new' expression  

Reports array initializers without new array expressions and suggests adding them.

Assignment can be joined with declaration  

Reports variable assignments that can be joined with a variable declaration.

Block marker comment  

Reports comments which are used as code block markers.

C-style array declaration  

Reports array declarations written in C-style syntax, where the array brackets are placed after a variable name or after a method parameter list.

Call to 'String.concat()' can be replaced with '+'  

Reports calls to java.lang.String.concat().

Can use bounded wildcard  

Reports generic method parameters that can make use of bounded wildcards.

Chained equality comparisons  

Reports chained equality comparisons.

Chained method calls  

Reports method calls whose target is another method call.

Class explicitly extends 'Object'  

Reports any classes that are explicitly declared to extend java.lang.Object.

Code block contains single statement  

Reports control flow statements with a single statement in their code block and suggests removing the braces from the control flow statement body.

Conditional can be replaced with Optional  

Reports null-check conditions and suggests replacing them with Optional chains.

Confusing octal escape sequence  

Reports string literals containing an octal escape sequence immediately followed by a digit.

Constant expression can be evaluated  

Reports constant expressions, whose value can be evaluated statically, and suggests replacing them with their actual values.

Constant on wrong side of comparison  

Reports comparison operations where the constant value is on the wrong side.

Control flow statement without braces  

Reports any if, while, do, or for statements without braces.

Diamond can be replaced with explicit type arguments  

Reports instantiation of generic classes in which the <> symbol (diamond) is used instead of type parameters.

Field assignment can be moved to initializer  

Suggests replacing initialization of fields using assignment with initialization in the field declaration.

Field may be 'final'  

Reports fields that can be safely made final.

Implicit call to 'super()'  

Reports constructors that do not begin with a call to "super" constructor or another constructor of the same class.

Instance field access not qualified with 'this'  

Reports field access operations that are not qualified with this or some other qualifier.

Instance method call not qualified with 'this'  

Reports calls to non-static methods on the same instance that are not qualified with this.

Labeled switch rule can have code block  

Reports rules of switch expressions or enhanced switch statements with an expression body.

Labeled switch rule has redundant code block  

Reports labeled rules of switch statements or switch expressions that have a redundant code block.

Lambda body can be code block  

Reports lambdas whose body is an expression and suggests converting expression bodies to code blocks.

Lambda can be replaced with anonymous class  

Reports lambda expressions that can be replaced with anonymous classes.

Lambda parameter type can be specified  

Reports lambda parameters that do not have their type specified and suggests adding the missing type declarations.

Local variable or parameter can be 'final'  

Reports parameters or local variables that may have the final modifier added to their declaration.

Method reference can be replaced with lambda  

Reports method references, like MyClass::myMethod and myObject::myMethod, and suggests replacing them with an equivalent lambda expression.

Missorted modifiers  

Reports declarations whose modifiers are not in the canonical preferred order (as stated in the Java Language Specification).

Multi-catch can be split into separate catch blocks  

Reports multi-catch sections and suggests splitting them into separate catch blocks.

Multiple operators with different precedence  

Reports binary, conditional, or instanceof expressions that consist of different operators without parentheses.

Multiple variables in one declaration  

Reports multiple variables that are declared in a single declaration and suggest creating a separate declaration for each variable.

Nested method call  

Reports method calls used as parameters to another method call.

Non functional style 'Optional.isPresent()' usage  

Reports Optional expressions used as if or conditional expression conditions, that can be rewritten in a functional style.

Non-normalized annotation  

Reports annotations in a shorthand form and suggests rewriting them in a normal form with an attribute name.

Non-terminal use of '\s' escape sequence  

Reports \s escape sequences anywhere except at text-block line endings or within a series of several escaped spaces.

Reassigned variable  

Reports reassigned variables, which complicate reading and understanding the code.

Record can be converted to class  

Reports record classes and suggests converting them to ordinary classes.

Redundant 'new' expression in constant array creation  

Reports constant new array expressions that can be replaced with an array initializer.

Redundant field initialization  

Reports fields explicitly initialized to their default values.

Redundant no-arg constructor  

Reports unnecessary constructors.

Return of 'this'  

Reports methods returning this.

Same file subclasses are missing from permits clause of a sealed class  

Reports sealed classes whose permits clauses do not contain some of the subclasses from the same file.

Simplifiable annotation  

Reports annotations that can be simplified to their single-element or marker shorthand form.

Standard 'Charset' object can be used  

Reports methods and constructors in which constant charset String literal (for example, "UTF-8") can be replaced with the predefined StandardCharsets.UTF_8 code.

Stream API call chain can be replaced with loop  

Reports Stream API chains, Iterable.forEach(), and Map.forEach() calls that can be automatically converted into classical loops.

String literal may be 'equals()' qualifier  

Reports String.equals() or String.equalsIgnoreCase() calls with a string literal argument.

Subsequent steps can be fused into Stream API chain  

Detects transformations outside a Stream API chain that could be incorporated into it.

Trailing whitespace in text block  

Reports text blocks with trailing whitespace characters.

Type parameter explicitly extends 'Object'  

Reports type parameters and wildcard type arguments that are explicitly declared to extend java.lang.Object.

Unnecessarily qualified inner class access  

Reports any references to inner classes that are unnecessarily qualified with the name of the enclosing class.

Unnecessarily qualified static access  

Reports usages of static members unnecessarily qualified with the class name.

Unnecessarily qualified statically imported element  

Reports usage of statically imported members qualified with their containing class name.

Unnecessary 'final' on local variable or parameter  

Reports local variables or parameters unnecessarily declared final.

Unnecessary 'null' check before 'equals()' call  

Reports comparisons to null that are followed by a call to equals() with a constant argument.

Unnecessary 'super' qualifier  

Reports unnecessary super qualifiers in method calls and field references.

Unnecessary 'this' qualifier  

Reports unnecessary this qualifier.

Unnecessary call to 'super()'  

Reports calls to no-arg superclass constructors during object construction.

Unnecessary call to 'toString()'  

Reports calls to toString() that are used in the following cases: In string concatenations In the java.lang.StringBuilder#append() or java.lang.StringBuffer#append() methods In the methods of java.io.PrintWriter or java.io.PrintStream in the methods org.slf4j.Logger In these cases, conversion to string will be handled by the underlying library methods, and the explicit call to toString() is not needed.

Unnecessary code block  

Reports code blocks that are redundant to the semantics of the program and can be replaced with their contents.

Unnecessary conversion to 'String'  

Reports unnecessary calls to static methods that convert their parameters to a string, e.g.

Unnecessary fully qualified name  

Reports fully qualified class names that can be shortened.

Unnecessary modifier  

Reports redundant modifiers and suggests to remove them.

Unnecessary parentheses  

Reports any instance of unnecessary parentheses.

Unnecessary qualifier for 'this' or 'super'  

Reports unnecessary qualification of this or super.

Unnecessary semicolon  

Reports any unnecessary semicolons, including semicolons that are used between class members, inside block statements, or after class definitions.

Unqualified inner class access  

Reports references to inner classes that are not qualified with the name of the enclosing class.

Unqualified static access  

Reports usage of static members that is not qualified with the class name.

Using 'instanceof' with patterns  

Reports instanceof with patterns and suggests converting them to ordinary instanceof with casts.

Last modified: 18 June 2024