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,
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
BigDecimal, and so on, and of utility classes like
random()). The well-known methods, such as
Comparator.compare() 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.
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
Expression complexity threshold
IntelliJ IDEA 2023.3, Qodana for JVM 2023.3