Skip to content

Convert eligible classes to records #17299

@AmitKumarDeoghoria

Description

@AmitKumarDeoghoria

From comment : #17259 (comment)
During the JDK 17 upgrade (#17168), we've identified multiple classes that can be converted to Java records. To keep the initial migration focused and manageable, we're temporarily disabling these inspections. This follow-up issue tracks the conversion of these classes to leverage JDK 17's record feature for cleaner, more maintainable code.

Any classes in "api" package should not be changed!!!

<problems is_local_tool="true">
<problem>
<file>file://$PROJECT_DIR$/src/main/java/com/puppycrawl/tools/checkstyle/TreeWalkerAuditEvent.java</file>
<line>30</line>
<module>project</module>
<package>com.puppycrawl.tools.checkstyle</package>
<entry_point TYPE="class" FQNAME="com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent"/>
<problem_class id="ClassCanBeRecord" severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Class can be a record</problem_class>
<description>Class can be a record</description>
<highlighted_element>TreeWalkerAuditEvent</highlighted_element>
<language>JAVA</language>
<offset>13</offset>
<length>20</length>
</problem>
<problem>
<file>file://$PROJECT_DIR$/src/main/java/com/puppycrawl/tools/checkstyle/api/LineColumn.java</file>
<line>28</line>
<module>project</module>
<package>com.puppycrawl.tools.checkstyle.api</package>
<entry_point TYPE="class" FQNAME="com.puppycrawl.tools.checkstyle.api.LineColumn"/>
<problem_class id="ClassCanBeRecord" severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Class can be a record</problem_class>
<description>Class can be a record</description>
<highlighted_element>LineColumn</highlighted_element>
<language>JAVA</language>
<offset>13</offset>
<length>10</length>
</problem>
<problem>
<file>file://$PROJECT_DIR$/src/main/java/com/puppycrawl/tools/checkstyle/site/AllCheckSummaries.java</file>
<line>839</line>
<module>project</module>
<package>com.puppycrawl.tools.checkstyle.site</package>
<entry_point TYPE="class" FQNAME="com.puppycrawl.tools.checkstyle.site.AllCheckSummaries.CheckInfo"/>
<problem_class id="ClassCanBeRecord" severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Class can be a record</problem_class>
<description>Class can be a record</description>
<highlighted_element>CheckInfo</highlighted_element>
<language>JAVA</language>
<offset>31</offset>
<length>9</length>
</problem>
</problems>

Action Plan:

  • Re-enable ClassCanBeRecord inspections in IDE/config

  • Convert each listed class to Java record syntax

  • Migrate validation logic to compact constructors

  • Update getter references to record accessors

  • Verify behavior with existing test cases

LineColumn - please send PR to put a suppression comment, to avoid problems with compatibility on user side.
AllCheckSummaries.CheckInfo - must be changed, east fix.
TreeWalkerAuditEvent - we can change, as we doing jdk21 update, for 13.0.0 version will be good version to point user to breaking changes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions