Inspectopedia Help

Probable bugs

'Comparable' implemented but 'equals()' not overridden  

Reports classes that implement java.lang.Comparable but do not override equals().

'Iterator.hasNext()' which calls 'next()'  

Reports implementations of Iterator.hasNext() or ListIterator.hasPrevious() that call Iterator.next() or ListIterator.previous() on the iterator instance.

'Iterator.next()' which can't throw 'NoSuchElementException'  

Reports implementations of Iterator.next() that cannot throw java.util.NoSuchElementException.

'Math.random()' cast to 'int'  

Reports calls to Math.random() which are immediately cast to int.

'ScheduledThreadPoolExecutor' with zero core threads  

Reports any java.util.concurrent.ScheduledThreadPoolExecutor instances in which corePoolSize is set to zero via the setCorePoolSize method or the object constructor.

'String.equals()' called with 'CharSequence' argument  

Reports calls to String.equals() with a CharSequence as the argument.

'Throwable' not thrown  

Reports instantiations of Throwable or its subclasses, where the created Throwable is never actually thrown.

'assert' statement with side effects  

Reports assert statements that cause side effects.

'equal()' instead of 'equals()'  

Reports declarations of equal() with a single parameter.

'equals()' and 'hashCode()' not paired  

Reports classes that override the equals() method but do not override the hashCode() method or vice versa, which can potentially lead to problems when the class is added to a Collection or a HashMap.

'equals()' between objects of inconvertible types  

Reports calls to equals() where the target and argument are of incompatible types.

'equals()' called on array  

Reports equals() calls that compare two arrays.

'equals()' called on classes which don't override it  

Reports equals() calls on StringBuilder, StringBuffer and instances of java.util.concurrent.atomic package.

'equals()' called on itself  

Reports calls to equals(), compareTo() or similar, that compare an object for equality with itself.

'equals()' method which does not check class of parameter  

Reports equals() methods that do not check the type of their parameter.

'hashCode()' called on array  

Reports incorrect hash code calculation for arrays.

'instanceof' with incompatible type  

Reports instanceof expressions where the expression that is checked has a class/interface type that neither extends/implements the class/interface type on the right-side of the instanceof expression, nor has subclasses that do.

Array comparison using '==', instead of 'Arrays.equals()'  

Reports operators == and != used to test for array equality.

Call math rounding with 'int' argument  

Reports calls to round(), ceil(), floor(), rint() methods for Math and StrictMath with int as the argument.

Call methods with unsupported 'java.time.temporal.ChronoUnit' and 'java.time.temporal.ChronoField'  

Reports java.time method calls (get(), getLong(), with(), plus(), minus()) with unsupported java.time.temporal.ChronoField or java.time.temporal.ChronoUnit enum constants as arguments.

Call to 'toString()' on array  

Reports arrays used in String concatenations or passed as parameters to java.io.PrintStream methods, such as System.out.println().

Call to default 'toString()'  

Reports calls to toString() that use the default implementation from java.lang.Object.

Cast conflicts with 'instanceof'  

Reports type cast expressions that are preceded by an instanceof check for a different type.

Cast to incompatible type  

Reports type cast expressions where the casted expression has a class/interface type that neither extends/implements the cast class/interface type, nor has subclasses that do.

Cleaner captures object reference  

Reports Runnable passed to a Cleaner.register() capturing reference being registered.

Collection added to itself  

Reports cases where the argument of a method call on a java.util.Collection or java.util.Map is the collection or map itself.

Confusing 'main()' method  

Reports methods that are named "main", but do not have the public static void main(String[]) signature in Java up to 21.

Confusing argument to varargs method  

Reports calls to variable arity methods that have a single argument in the vararg parameter position, which is either a null or an array of a subtype of the vararg parameter.

Confusing primitive array argument to varargs method  

Reports any calls to a variable arity method where the call has a primitive array in the variable arity parameter position (for example, System.out.printf("%s", new int[]{1, 2, 3})).

Constant condition in 'assert' statement  

Reports assert statement conditions that are constants.

Constant values  

Reports expressions and conditions that always produce the same result, like true, false, null, or zero.

Contract issues  

Reports issues in method @Contract annotations.

Copy constructor misses field  

Reports copy constructors that don't copy all the fields of the class.

Covariant 'equals()'  

Reports equals() methods taking an argument type other than java.lang.Object if the containing class does not have other overloads of equals() that take java.lang.Object as its argument type.

Duplicated delimiters in 'StringTokenizer'  

Reports StringTokenizer() constructor calls or nextToken() method calls that contain duplicate characters in the delimiter argument.

Inconsistent whitespace indentation in text block  

Reports text blocks that are indented using both spaces and tabs.

Incorrect 'DateTimeFormat' pattern  

Reports incorrect date time format patterns.

Incorrect 'MessageFormat' pattern  

Reports incorrect message format patterns or incorrect indexes of placeholders The following errors are reported: Unparsed or negative index Unclosed brace Unpaired quote.

Infinite recursion  

Reports methods that call themselves infinitely unless an exception is thrown.

Inner class referenced via subclass  

Reports accesses of inner and nested classes where the call is qualified by a subclass of the declaring class, rather than the declaring class itself.

Instantiation of utility class  

Reports instantiation of utility classes using the new keyword.

Invalid method reference used for 'Comparator'  

Reports method references mapped to the Comparator interface that don't fulfill its contract.

Iterable is used as vararg  

Reports suspicious usages of Collection or Iterable in vararg method calls.

Loop executes zero or billions of times  

Reports loops that cannot be completed without an index overflow or loops that don't loop at all.

Magic constant  

Reports expressions that can be replaced with "magic" constants.

Malformed format string  

Reports format strings that don't comply with the standard Java syntax.

Meaningless record annotation  

Reports annotations used on record components that have no effect.

Mismatched case in 'String' operation  

Reports String method calls that always return the same value (-1 or false) because a lowercase character is searched in an uppercase-only string or vice versa.

Mismatched query and update of 'StringBuilder'  

Reports StringBuilder, StringBuffer or StringJoiner objects whose contents are read but not written to, or written to but not read.

Mismatched query and update of collection  

Reports collections whose contents are either queried and not updated, or updated and not queried.

Mismatched read and write of array  

Reports arrays whose contents are read but not updated, or updated but not read.

New object is compared using '=='  

Reports code that applies == or != to a newly allocated object instead of calling equals().

Non-final field referenced in 'compareTo()'  

Reports access to a non-final field inside a compareTo() implementation.

Non-final field referenced in 'equals()'  

Reports implementations of equals() that access non-final variables.

Non-final field referenced in 'hashCode()'  

Reports implementations of hashCode() that access non-final variables.

Non-short-circuit boolean expression  

Reports usages of the non-short-circuit forms of boolean 'and' and 'or' (&, |, &= and |=).

Non-short-circuit operation consumes infinite stream  

Reports non-short-circuit operations consuming an infinite stream.

Nullability and data flow problems  

Reports code constructs that always violate nullability contracts, may throw exceptions, or are just redundant, based on data flow analysis.

Number comparison using '==', instead of 'equals()'  

Reports code that uses == or != instead of equals() to test for Number equality.

Object comparison using '==', instead of 'equals()'  

Reports code that uses == or != rather than equals() to test for object equality.

Optional.get() is called without isPresent() check  

Reports calls to get() on an Optional without checking that it has a value.

Overwritten Map, Set, or array element  

Reports code that overwrites a Map key, a Set element, or an array element in a sequence of add/put calls or using a Java 9 factory method like Set.of (which will result in runtime exception).

Redundant operation on empty container  

Reports redundant operations on empty collections, maps or arrays.

Reference checked for 'null' is not used inside 'if'  

Reports references to variables that are checked for nullability in the condition of an if statement or conditional expression but not used inside that if statement.

Reflective access to a source-only annotation  

Reports attempts to reflectively check for the presence of a non-runtime annotation.

Result of method call ignored  

Reports method calls whose result is ignored.

Result of object allocation ignored  

Reports object allocations where the allocated object is ignored and neither assigned to a variable nor used in another way.

Sorted collection with non-comparable elements  

Reports construction of sorted collections, for example TreeSet, that rely on natural ordering, whose element type doesn't implement the Comparable interface.

Statement with empty body  

Reports if, while, do, for, and switch statements with empty bodies.

Static field referenced via subclass  

Reports accesses to static fields where the call is qualified by a subclass of the declaring class, rather than by the declaring class itself.

Static method referenced via subclass  

Reports static method calls where the call is qualified by a subclass of the declaring class, rather than by the declaring class itself.

String comparison using '==', instead of 'equals()'  

Reports code that uses of == or != to compare strings.

String concatenation as argument to 'MessageFormat.format()' call  

Reports non-constant string concatenations used as an argument to a call to MessageFormat.format().

String concatenation as argument to 'format()' call  

Reports non-constant string concatenations used as a format string argument.

StringBuilder constructor call with 'char' argument  

Reports calls to StringBuffer and StringBuilder constructors with char as the argument.

Subtraction in 'compareTo()'  

Reports subtraction in compareTo() methods and methods implementing java.util.Comparator.compare().

Suspicious 'Arrays' method call  

Reports calls to non-generic-array manipulation methods like Arrays.fill() with mismatched argument types.

Suspicious 'Class.getClass()' call  

Reports getClass() methods that are called on a java.lang.Class instance.

Suspicious 'Collection.toArray()' call  

Reports suspicious calls to Collection.toArray().

Suspicious 'Comparator.compare()' implementation  

Reports problems in Comparator.compare() and Comparable.compareTo() implementations.

Suspicious 'InvocationHandler' implementation  

Reports implementations of InvocationHandler that do not proxy standard Object methods like hashCode(), equals(), and toString().

Suspicious 'List.remove()' in loop  

Reports list.remove(index) calls inside an ascending counted loop.

Suspicious 'System.arraycopy()' call  

Reports suspicious calls to System.arraycopy().

Suspicious array cast  

Reports suspicious array casts.

Suspicious byte value returned from 'InputStream.read()'  

Reports expressions of byte type returned from a method implementing the InputStream.read() method.

Suspicious collection method call  

Reports method calls on parameterized collections, where the actual argument type does not correspond to the collection's elements type.

Suspicious date format pattern  

Reports date format patterns that are likely used by mistake.

Suspicious indentation after control statement without braces  

Reports suspicious indentation of statements after a control statement without braces.

Suspicious integer division assignment  

Reports assignments whose right side is a division that shouldn't be truncated to integer.

Suspicious regex expression argument  

Reports calls to String.replaceAll() or String.split() where the first argument is a single regex meta character argument.

Suspicious ternary operator in varargs method call  

Reports vararg method calls that use a ternary operator with mixed array and non-array branches.

Suspicious usage of compare method  

Reports comparisons of the result of Comparator.compare() or Comparable.compareTo() calls with non-zero constants.

Suspicious variable/parameter name combination  

Reports assignments and function calls in which the name of the target variable or the function parameter does not match the name of the value assigned to it.

Text label in 'switch' statement  

Reports labeled statements inside of switch statements.

Unreachable code  

Reports the code which is never reached according to data flow analysis.

Unsafe call to 'Class.newInstance()'  

Reports calls to java.lang.Class.newInstance().

Unused assignment  

Reports assignment values that are not used after assignment.

Use of 'Properties' object as a 'Hashtable'  

Reports calls to the following methods on java.util.Properties objects: put() putIfAbsent() putAll() get() For historical reasons, java.util.Properties inherits from java.util.Hashtable, but using these methods is discouraged to prevent pollution of properties with values of types other than String.

Use of Optional.ofNullable with null or not-null argument  

Reports uses of Optional.ofNullable() where always null or always not-null argument is passed.

Use of index 0 in JDBC ResultSet  

Reports attempts to access column 0 of java.sql.ResultSet or java.sql.PreparedStatement.

Use of shallow or 'Objects' methods with arrays  

Reports expressions that seem to use an inappropriate method for determining array equality or calculating their hashcode.

Whitespace may be missing in string concatenation  

Reports string concatenations with missing whitespaces, that is where the left-hand side ends with a Unicode letter or digit and the right-hand side starts with a Unicode letter or digit.

Write-only object  

Reports objects that are modified but never queried.

Wrong package statement  

Detects package statements that do not correspond to the project directory structure.

Nullability problems  

Sub-group of 4 inspections that provide checks for Nullability problems

Last modified: 18 June 2024