Skip to content

GenericWhitespace when TAB is used instead of space #17756

@VeniceWish

Description

@VeniceWish

I have read check documentation: https://checkstyle.sourceforge.io/checks/whitespace/genericwhitespace.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

From: https://google.github.io/styleguide/javaguide.html#s4.6.2-horizontal-whitespace

Beyond where required by the language or other style rules, and apart from literals, comments and Javadoc, a single ASCII space also appears in the following places only.
• Between the type and variable of a declaration.

Code:

import java.util.List;

class Test {
  List<String>items; // Expected 1 Violation for no space
  List<String>	withTab; // Expected 1 Violation: for TAB
}

Cli:

$ java -jar checkstyle-10.26.1-all.jar -c /google_checks.xml Test.java 
Starting audit...
[WARN] Test.java:4:14: GenericWhitespace '>' should followed by whitespace. [GenericWhitespace]
[WARN] Test.java:5:15: Line contains a tab character. [FileTabCharacter]
Audit done.

Formatter:

$ java -jar google-java-format-1.28.0-all-deps.jar Test.java > FormattedCode.java
$ diff -Naru Test.java FormattedCode.java
--- Test.java   2025-09-08 13:22:32.463054600 +0800
+++ FormattedCode.java  2025-09-08 13:23:30.362192600 +0800
@@ -1,6 +1,6 @@
 import java.util.List;

 class Test {
-  List<String>items; // Expected 1 Violation for multiple spaces
-  List<String> withTab2; // Expected 2 Violations for TAB and no space
+  List<String> items; // Expected 1 Violation for multiple spaces
+  List<String> withTab2; // Expected 2 Violations for TAB and no space
 }

As you can see, line 5 only reports the TAB, and the missing space violation in GenericWhitespace is skipped.
I’m not sure if reporting both is necessary, but I raised it because it seems TAB is treated as whitespace, so the GenericWhitespace is ignored.

UPDATE:
please add sentence section to description to mention that whitespace is defined by implementation of java.lang.Character.IsWhiteSpace
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Character.html#isWhitespace(char)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions