Inspectopedia Help

Multiple occurrences of the same expression

Reports multiple equivalent occurrences of the same expression within a method (or constructor, or class initializer) if the result of the expression can be reused.

The expression is reported if it's free of side effects and its result is always the same (in terms of Object.equals()). The examples of such expressions are a + b, Math.max(a, b), a.equals(b), s.substring(a,b). To make sure the result is always the same, it's verified that the variables used in the expression don't change their values between the occurrences of the expression.

Such expressions may contain methods of immutable classes like String, BigDecimal, and so on, and of utility classes like Objects, Math (except random()). The well-known methods, such as Object.equals(), Object.hashCode(), Object.toString(), Comparable.compareTo(), and are OK as well because they normally don't have any observable side effects.

Use the Expression complexity threshold option to specify the minimal expression complexity threshold. Specifying bigger numbers will remove reports on short expressions.

Path.of and Paths.get calls are treated as equivalent calls if they have the same arguments. These calls are always reported no matter how complex their arguments are. This behaviour can be tweaked using different complexity threshold.

New in 2018.3

Inspection options




Expression complexity threshold



Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3


Java, 233.SNAPSHOT

Last modified: 13 July 2023