mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
28 lines
1.1 KiB
HTML
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> |