mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
28 lines
1009 B
HTML
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> |