Inspectopedia 2024.3 Help

Non-terminal use of '\s' escape sequence

Reports \s escape sequences anywhere except at text-block line endings or within a series of several escaped spaces. Such usages can be confusing or a mistake, especially if the string is interpreted as a regular expression. 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 or char literals, \s is identical to an ordinary space character (" ").

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.

A quick-fix is provided that replaces \s escapes with space characters.

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

EscapedSpace
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Code style issues

This inspection depends on the Java feature ''\s' escape sequences', which is available since Java 15.

New in 2022.3

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.3, Qodana for JVM 2024.3,

Can be installed with plugin:

Java, 243.23126

Last modified: 03 December 2024