Files
openide/java/java-impl/resources/inspectionDescriptions/ReplaceAllDot.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
1009 B
HTML

<html>
<body>
Reports calls to
<code>String.replaceAll()</code> or <code>String.split()</code> where the first argument is a single regex meta character argument.
<p>
The regex meta characters are one of <code>.$|()[{^?*+\</code>. They have a special meaning in regular expressions.
For example, calling <code>"ab.cd".replaceAll(".", "-")</code> produces <code>"-----"</code>, because the dot matches any character.
Most likely the escaped variant <code>"\\."</code> was intended instead.
</p>
<p>
Using <code>File.separator</code> as a regex is also reported. The <code>File.separator</code> has a platform specific value. It
equals to <code>/</code> on Linux and Mac but equals to <code>\</code> on Windows, which is not a valid regular expression, so
such code is not portable.
</p>
<p><b>Example:</b></p>
<pre><code>
s.replaceAll(".", "-");
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code>
s.replaceAll("\\.", "-");
</code></pre>
<!-- tooltip end -->
<p>
</body>
</html>