Repository navigation
Description
https://google.github.io/styleguide/javaguide.html#s2.3.2-special-escape-sequences
2.3.2 Special escape sequences
For any character that has a special escape sequence (\b, \t, \n, \f, \r, \s, ", ' and \), that sequence is used rather than the corresponding octal (e.g. \012) or Unicode (e.g. \u000a) escape.
I have read check documentation: https://checkstyle.org/checks/coding/illegaltokentext.html
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words
Code:
$ cat EscapedCodes.java
class EscapedCodes {
public void unicode() {
final String r0 = "\s";
final String r1 = "\u000b"; // Expected violation
final String r2 = "\u000c"; // OK
final String r3 = "\u001c"; // Expected violation
final String r4 = "\u001D"; // Expected violation
final String r5 = "\u001E"; // Expected violation
final String r6 = "\u001F"; // Expected violation
final String r7 = "\u1680"; // Expected violation
final String r8 = "\u2000"; // Expected violation
final String r9 = "\u200A"; // Expected violation
final String r10 = "\u2028"; // Expected violation
final String r12 = "\u2029"; // Expected violation
final String r13 = "\u202F"; // Expected violation
final String r14 = "\u205F"; // Expected violation
final String r15 = "\u3000"; // Expected violation
}
public void octal() {
final String r1 = "\040"; // Expected violation
final String r2 = "\011"; // ok
final String r3 = "\012"; // ok
}
}Cli:
$ java -jar checkstyle-10.26.1-all.jar -c google_checks.xml EscapedCodes.java
Starting audit...
[WARN] /mnt/5D92528E6B945467/test/testing/EscapedCodes.java:5:23: Consider using special escape sequence instead of octal value or Unicode escaped value. [IllegalTokenText]
[WARN] /mnt/5D92528E6B945467/test/testing/EscapedCodes.java:22:23: Consider using special escape sequence instead of octal value or Unicode escaped value. [IllegalTokenText]
[WARN] /mnt/5D92528E6B945467/test/testing/EscapedCodes.java:23:23: Consider using special escape sequence instead of octal value or Unicode escaped value. [IllegalTokenText]
Audit done.
https://en.wikipedia.org/wiki/Whitespace_character
For example, a space character (U+0020 SPACE, ASCII 32) represents blank space such as a word divider in a Western script.
The 040 part is the octal (base-8) representation of the ASCII code for the space character, which is decimal 32.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
romani commentedon Aug 5, 2025
how did you map
\sto\u2028, please share link or any other resource.Issue checkstyle#17551: Violation on octal value of '\s'
mohitsatr commentedon Aug 12, 2025
@romani
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/regex/Pattern.html
U+2028(line separator) is the part of the table below
https://en.wikipedia.org/wiki/Whitespace_character
Issue checkstyle#17551: Violation on Unicode value of '\s'
Issue checkstyle#17551: Violation on Unicode value of '\s'
Issue #17551: Violation on octal value of '\s'
Issue checkstyle#17551: Violation on Unicode value of '\s'
Issue checkstyle#17551: Violation on Unicode value of '\s'
Issue checkstyle#17551: Violation on Unicode value of '\s'
Issue checkstyle#17551: Violation on Unicode value of '\s'
Issue #17551: Violation on Unicode value of '\s'
romani commentedon Aug 16, 2025
Final fix is merged
lrozenblyum commentedon Jan 7, 2026
Sorry for commenting on the old thread, however: what's the suggested replacement for
"\u202F"or similar characters which need to be referenced in the code?Which 'escape sequence' is supposed to reflect it? @mohitsatr
romani commentedon Jan 8, 2026
https://www.compart.com/en/unicode/U+202F looks like invisible symbol, @lrozenblyum , please create issue on this, if you think that Google style validation should skip validation on it
lrozenblyum commentedon Jan 8, 2026
@romani yes I can create an issue for sure.
Just would like to understand @mohitsatr motivation on this issue reporting.
Most of the characters that are now banned due to this rule have no escape sequences to replace them by.
romani commentedon Jan 8, 2026
https://google.github.io/styleguide/javaguide.html#s2.3.2-special-escape-sequences
This paragraph was motivation.
lrozenblyum commentedon Jan 8, 2026
@romani according to https://docs.oracle.com/javase/specs/jls/se21/html/jls-3.html#jls-3.10.7
\sstands for\u0020and that's all.Either I'm misunderstanding the spec, or the current issue was not a proper false negative report.
Maybe escape sequence
\swas confused with the predefined character in regexp where indeed it can cover much more characters.For all the characters mentioned above as false negatives there are no escape sequences!
I'd suggest reverting the whole change...
Issue checkstyle#18616: Revert PR checkstyle#17551 to fix false posit…