Files
openide/java/java-impl/resources/inspectionDescriptions/EqualsOnSuspiciousObject.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

27 lines
1.1 KiB
HTML

<html>
<body>
Reports <code>equals()</code> calls on <code>StringBuilder</code>, <code>StringBuffer</code> and instances of
<code>java.util.concurrent.atomic</code> package.
<p>The <code>equals()</code> method is not overridden in these classes, so it may return <code>false</code> even when the contents of the
two objects are the same.
If the reference equality is intended, it's better to use <code>==</code> to avoid confusion.</p>
A quick-fix for <code>StringBuilder</code>, <code>StringBuffer</code>, <code>AtomicBoolean</code>,
<code>AtomicInteger</code>, <code>AtomicBoolean</code> and <code>AtomicLong</code> is available
to transform into a comparison of contents.
The quick-fix may change the semantics when one of the instances is null.
<p>Example:</p>
<pre><code>
public void test(StringBuilder sb1, StringBuilder sb2) {
boolean result = sb1.equals(sb2); // Suspicious
}
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code>
public void test(StringBuilder sb1, StringBuilder sb2) {
boolean result = sb1.toString().equals(sb2.toString());
}
</code></pre>
<!-- tooltip end -->
<p><small>New in 2017.2</small></p>
</body>
</html>