Skip to content

Missing violations on Unicode and Octal values of \s #17551

Closed

Description

@mohitsatr

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.

Activity

  1. romani commented on Aug 5, 2025

    @romani
    Member

    how did you map \s to \u2028 , please share link or any other resource.

  2. added
    false negativeissues where check should place violations on code, but does not
    on Aug 5, 2025
  3. added a commit that references this issue on Aug 12, 2025
  4. mohitsatr commented on Aug 12, 2025

    @mohitsatr
    MemberAuthor

    @romani

    https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/regex/Pattern.html

    Image

    \s
    A whitespace character: [ \t\n\x0B\f\r] if UNICODE_CHARACTER_CLASS is not set. See Unicode Support.

    U+2028(line separator) is the part of the table below

    https://en.wikipedia.org/wiki/Whitespace_character

    The table below lists the twenty-five characters defined as whitespace ("WSpace=Y", "WS") characters in the Unicode Character Database

    Image
  5. added 2 commits that reference this issue on Aug 12, 2025
  6. deleted a comment from mohitsatr on Aug 12, 2025
  7. added a commit that references this issue on Aug 13, 2025
  8. added this to the 11.0.1 milestone on Aug 13, 2025
  9. added 4 commits that reference this issue on Aug 14, 2025
  10. added a commit that references this issue on Aug 16, 2025
  11. romani commented on Aug 16, 2025

    @romani
    Member

    Final fix is merged

  12. lrozenblyum commented on Jan 7, 2026

    @lrozenblyum

    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

  13. romani commented on Jan 8, 2026

    @romani
    Member

    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

  14. lrozenblyum commented on Jan 8, 2026

    @lrozenblyum

    @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.

  15. romani commented on Jan 8, 2026

    @romani
    Member
  16. lrozenblyum commented on Jan 8, 2026

    @lrozenblyum

    @romani according to https://docs.oracle.com/javase/specs/jls/se21/html/jls-3.html#jls-3.10.7
    \s stands for \u0020 and that's all.

    Either I'm misunderstanding the spec, or the current issue was not a proper false negative report.

    Maybe escape sequence \s was 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...

  17. added a commit that references this issue on Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions