Skip to content

Add RECORD_DEF and COMPACT_CTOR_DEF to AtclauseOrder target in google_checks.xml #19682

@vivek-0509

Description

@vivek-0509

I have read check documentation: https://checkstyle.org/checks/javadoc/atclauseorder.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

vivek@Viveks-MacBook-Air checkstyle % cat > /var/tmp/TestFile.java << 'EOF'
/**
 * Class with wrong tag order, violation correctly reported.
 *
 * @deprecated old class
 * @param <T> the type
 */
class OldClass<T> {}

/**
 * Record with wrong tag order, violation NOT reported.
 *
 * @deprecated use NewPoint
 * @param x the x coordinate
 * @param y the y coordinate
 */
record OldPoint(int x, int y) {}

/**
 * Record with compact ctor that has wrong tag order, violation NOT reported.
 */
record AnotherPoint(int x, int y) {
  /**
   * Validates coordinates.
   *
   * @deprecated use factory method
   * @param x the x
   * @param y the y
   */
  AnotherPoint {}
}
EOF

vivek@Viveks-MacBook-Air checkstyle % java -Duser.language=en -Duser.country=US -jar target/checkstyle-13.4.1-SNAPSHOT-all.jar -c google_checks.xml /var/tmp/TestFile.java
Starting audit...
[WARN] /var/tmp/TestFile.java:5: Block tags have to appear in the order '[@param, @return, @throws, @deprecated]'. [AtclauseOrder]
[WARN] /var/tmp/TestFile.java:7:1: The name of the outer type and the file do not match. [OuterTypeFilename]
[WARN] /var/tmp/TestFile.java:16:1: Top-level class OldPoint has to reside in its own source file. [OneTopLevelClass]
[WARN] /var/tmp/TestFile.java:21:1: Top-level class AnotherPoint has to reside in its own source file. [OneTopLevelClass]
Audit done.

Describe what you expect in detail.

I expect 3 violations, one for OldClass, one for OldPoint (record), and one for AnotherPoint's compact constructor. Only 1 violation is reported because RECORD_DEF and COMPACT_CTOR_DEF are missing from the target property of AtclauseOrder in google_checks.xml.

The AtclauseOrder module in google_checks.xml configures the target property with:

CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF

This omits RECORD_DEF and COMPACT_CTOR_DEF. Both tokens are present in AtclauseOrderCheck's default target initialization and are fully supported, they are simply not configured in google_checks.xml. Because the target property in google_checks.xml overrides the check's defaults, the new tokens are effectively excluded.

Google Java Style Guide Section 7.1.3 (Block tags) defines the tag ordering rule universally, it does not exclude records.

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