[java] mention performance in inspection description (IJ-CR-129155)

GitOrigin-RevId: afd288ea265904dd5446fc24c092cb650d986abd
This commit is contained in:
Bas Leijdekkers
2024-03-21 11:04:27 +00:00
committed by intellij-monorepo-bot
parent 39048a192b
commit b31dc2acb9
@@ -7,7 +7,9 @@ Reports calls to <code>toString()</code> that are used in the following cases:
<li>In the methods of <code>java.io.PrintWriter</code> or <code>java.io.PrintStream</code></li>
<li>in the methods <code>org.slf4j.Logger</code></li>
</ul>
<p>In these cases, conversion to string will be handled by the underlying library methods, and the explicit call to <code>toString()</code> is not needed.</p>
<p>In these cases, conversion to string will be handled by the underlying library methods,
and the explicit call to <code>toString()</code> is not needed.
Removing redundant <code>toString()</code> calls can occasionally even improve performance and reduce object allocations</p>
<p>Example:</p>
<pre><code>
System.out.println(this.toString())
@@ -21,6 +23,8 @@ Reports calls to <code>toString()</code> that are used in the following cases:
Note that without the <code>toString()</code> call, the code semantics might be different: if the expression is null,
then the <code>null</code> string will be used instead of throwing a <code>NullPointerException</code>.</p>
<p>Use the <b>Report only when qualifier is known to be not-null</b> option to avoid warnings for the values that could potentially be null.
Removing the explicit <code>toString()</code> in these cases will change the runtime semantics
from throwing a <code>NullPointException</code> to silently accepting the value when it is <code>null</code>.
</p>
</body>
</html>