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 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.
New in 2018.3