Inspectopedia 2025.2 Help

'equals()' called on classes which don't override it

Reports equals() calls on StringBuilder, StringBuffer and instances of java.util.concurrent.atomic package.

The equals() method is not overridden in these classes, so it may return false even when the contents of the two objects are the same. If the reference equality is intended, it's better to use == to avoid confusion.

A quick-fix for StringBuilder, StringBuffer, AtomicBoolean, AtomicInteger, AtomicBoolean and AtomicLong is available to transform into a comparison of contents. The quick-fix may change the semantics when one of the instances is null.

Example:

public void test(StringBuilder sb1, StringBuilder sb2) { boolean result = sb1.equals(sb2); // Suspicious }

After the quick-fix is applied:

public void test(StringBuilder sb1, StringBuilder sb2) { boolean result = sb1.toString().equals(sb2.toString()); }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

EqualsOnSuspiciousObject
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Probable bugs

New in 2017.2

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection EqualsOnSuspiciousObject

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

IntelliJ IDEA 2025.2, Qodana for JVM 2025.2,

Last modified: 18 September 2025