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

25 lines
948 B
HTML

<html>
<body>
Reports <code>synchronized</code> blocks that lock on an object initialized with a literal.
<p>
String literals are interned and <code>Character</code>, <code>Boolean</code> and <code>Number</code> literals can be allocated from a cache.
Because of this, it is possible that some other part of the system, which uses an object initialized with the same literal, is actually
holding a reference to the exact same object. This can create unexpected dead-lock situations, if the lock object was thought to be private.
</p>
<p><b>Example:</b></p>
<pre><code>
class Main {
final String mutex = "Mutex";
void method() {
synchronized (mutex) {
}
}
}
</code></pre>
<!-- tooltip end -->
<p>
Use the <strong>Warn on all possible literals</strong> option to report any synchronization on
<code>String</code>, <code>Character</code>, <code>Boolean</code> and <code>Number</code> objects.
</p>
</body>
</html>