Skip to content

Duplicate violations in WhitespaceAfter and WhitespaceAround in google config #17265

@mohitsatr

Description

@mohitsatr

From: #17236

Duplicate violations are getting logged for WhitespaceAround and WhitespaceAfter Checks in google_style

$ cat DuplicateError.java
/** some data. */
class DuplicateError {

  /** method. */
  void test(Object o) {
    switch (o) {
      case String s when (
          s.equals("a"))->{
      }
      default -> {}
    }
  }
}
$ java -jar checkstyle-10.25.0-all.jar -c google_checks.xml DuplicateError.java 
Starting audit...
[WARN] /mnt/5D92528E6B945467/test/testing/DuplicateError.java:8:25: '->' is not followed by whitespace. [WhitespaceAfter]
[WARN] /mnt/5D92528E6B945467/test/testing/DuplicateError.java:8:25: WhitespaceAround: '->' is not followed by whitespace. Empty blocks                may only be represented as {} when not part of a multi-block statement (4.1.3) [WhitespaceAround]
[WARN] /mnt/5D92528E6B945467/test/testing/DuplicateError.java:8:25: WhitespaceAround: '->' is not preceded with whitespace. [WhitespaceAround]
Audit done.

The first two violations are from different checks but they are saying the same thing so these violations are duplicate.

Following are some more examples from inputs:

}
// 2 violations 3 lines above:
// ''when' is not followed by whitespace.'
// ''when' is not followed by whitespace.'

public static class IntEnumValueType2<E extends Enum<E>& IntEnum> {
// 2 violations above:
// ''&' is not preceded with whitespace.'
// ''&' is not preceded with whitespace.'

while(x == 0) {
// 2 violations above:
// ''while' is not followed by whitespace.'
// ''while' is not followed by whitespace.'

} while(x == 0 || y == 2);
// 2 violations above:
// ''while' is not followed by whitespace.'
// ''while' is not followed by whitespace.'

try{
// 3 violations above:
// ''try' is not followed by whitespace.'
// ''try' is not followed by whitespace.'
// ''{' is not preceded with whitespace.'

In some case, the both violations in the config for WhitespaceAroundCheck's are getting triggered.

<message key="ws.notFollowed"
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks
may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>

Image

As part of the fix, we need to find out for which Tokens in config this overlapping is happening and fix it.

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