'equals()' called on itself
Reports calls to equals()
, compareTo()
or similar, that compare an object for equality with itself. The method contracts of these methods specify that such calls will always return true
for equals()
or 0
for compareTo()
. The inspection also checks calls to Objects.equals()
, Objects.deepEquals()
, Arrays.equals()
, Comparator.compare()
, assertEquals()
methods of test frameworks (JUnit, TestNG, AssertJ), Integer.compare()
, Integer.compareUnsigned()
and similar methods.
Example:
Use the option to report test assertions report only on non-extendable library classes (like String
) and primitive types. This option can be useful, when testing equals()
methods.
Inspection options
Option | Type | Default |
---|---|---|
Warn about test assertions only on final library class types or primitives | Checkbox | false |
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |