"\s"
escape sequence anywhere except text-block line endings or within series of several spaces.
The "\s"
escape sequence is intended to encode a space at the end of text-block lines where normal spaces are trimmed.
In other locations, as well as in regular string literals, "\s"
is identical to an ordinary space character (" "
).
Use of "\s"
is confusing and can be a mistake, especially if the string is interpreted as a regular expression.
Example:
if (str.matches("\s+")) {...}
Here it's likely that "\\s+"
was intended (to match any whitespace character). If not, using str.matches(" +")
would be less confusing.
The quick-fix is provided that simply replaces \s
with a space character.
This inspection reports only if the language level of the project or module is 15 or higher.
New in 2022.3