Inspectopedia Help

'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(),, assertEquals() methods of test frameworks (JUnit, TestNG, AssertJ),, Integer.compareUnsigned() and similar methods.


class Foo { boolean foo(Object o) { return o.equals(o); // warning } boolean bar(String[] ss) { return Arrays.equals(ss, ss); // warning } }

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




Warn about test assertions only on final library class types or primitives



Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3


Java, 233.SNAPSHOT

Last modified: 13 July 2023