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

28 lines
1.1 KiB
HTML

<html>
<body>
Reports non-constant string concatenations used as an argument to a call to
<code>MessageFormat.format()</code>.
<p>
While occasionally intended, this is usually a misuse of the formatting method
and may even cause unexpected exceptions if the variables used in the concatenated string contain
special characters like <code>{</code>.
</p>
<p>
Also, sometimes this could be the result
of mistakenly concatenating a string format argument by typing a <code>+</code> when a <code>,</code> was meant.
</p>
<p><b>Example:</b></p>
<pre><code>
String formatGreeting(String userName, int balance) {
return MessageFormat.format("Hello, " + userName + "! Your balance is {0}.", balance);
}
</code></pre>
<p>
Here, the <code>userName</code> will be interpreted as a part of the format string, which may result
in <code>IllegalArgumentException</code> (for example, if <code>userName</code> is <code>"{"</code>).
This call should be probably replaced with <code>MessageFormat.format("Hello, {0}! Your balance is {1}.", userName, balance)</code>.
</p>
<!-- tooltip end -->
</body>
</html>