-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Description
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 {
boolean withTab1; // Expected 2 Violations for TAB and no space
List<String>items; // Expected 1 Violation for no space
List<String> withTab2; // Expected 2 Violations for TAB and no space
int[]numbers; // Expected 1 Violation for no space
String[][] withTab3; // Expected 2 Violations for TAB and no space
}Cli:
$ java -jar checkstyle-10.26.1-all.jar -c google_checks.xml Test.java
Starting audit...
[WARN] Test.java:5:10: Line contains a tab character. [FileTabCharacter]
[WARN] Test.java:7:14: GenericWhitespace '>' should followed by whitespace. [GenericWhitespace]
[WARN] Test.java:8:15: Line contains a tab character. [FileTabCharacter]
[WARN] Test.java:11:13: 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-02 10:55:55.998605900 +0800
+++ FormattedCode.java 2025-09-02 10:56:09.892189400 +0800
@@ -1,13 +1,11 @@
import java.util.List;
-import java.util.Map;
class Test {
- boolean withTab1; // Expected 2 Violations for TAB and no space
+ boolean withTab1; // 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
-
- int[]numbers; // Expected 1 Violation for no space
- String[][] withTab3; // 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
+ int[] numbers; // Expected 1 Violation for no space
+ String[][] withTab3; // Expected 2 Violations for TAB and no space
}According to Google Style, there must be exactly one space between the type and the variable.
However
-
For cases like
int[]numbers, where there is no space at all between the array type and the variable, there is currently no check that reports this violation. -
When a TAB is used instead of a space, Checkstyle only reports
FileTabCharacter, and this seems to suppress the expected whitespace violation. This behavior appears in several checks, and might be by design — but it means the missing-space issue is not flagged.
As a result, both TAB instead of space and no space at all become false negatives in type–variable spacing.