Inspectopedia Help

Non-terminal use of '\s' escape sequence

Reports uses of "\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

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023