Skip to content

Convert eligible classes to records #17299

Closed

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.

Activity

  1. romani commented on Jun 30, 2025

    @romani
    Member

    We will make decision later on to follow this inspection or not.

    Some of them are API, we should not break.

    old scope of work:

    • AbstractXpathTestSupport.ViolationPosition
    • ThreadModeSettings
    • PropertyCacheFile.ExternalResource
    • TreeWalkerAuditEvent
    • LineColumn
    • SuppressWarningsHolder.Entry
    • RightCurlyCheck.Details
    • MultiFileRegexpHeaderCheck.MatchResult
    • MultiFileRegexpHeaderCheck.HeaderFileMetadata
    • CustomImportOrderCheck.ImportDetails
    • TagParser.Point
    • InvalidJavadocTag
    • TagInfo
    • TestInputViolation
    • BlockCommentPositionTest.BlockCommentPositionTestMetadata
    • CommitValidationTest.OmitMergeCommitsIterator
    • MessageLevelPair
  2. moved this from Todo to No status in Upgrade dependencieson Aug 17, 2025
  3. added 6 commits that reference this issue on Aug 23, 2025
  4. added a commit that references this issue on Aug 24, 2025
  5. added this to the 11.0.1 milestone on Aug 24, 2025
  6. 57 remaining items

  7. smita1078 commented on Jan 4, 2026

    @smita1078
    Member

    LineColumn is in the api package, so it's part of Checkstyle's public API. Converting it to a record would change the getter methods from getLine()/getColumn() to line()/column(), which would be a breaking change for external consumers. I think we should skip this one to maintain backward compatibility.

    Suppression comment can be there for such api packages

  8. added 4 commits that reference this issue on Jan 4, 2026
  9. added a commit that references this issue on Jan 4, 2026
  10. modified the milestones: 12.3.1, 13.0.0 on Jan 4, 2026
  11. added 3 commits that reference this issue on Jan 4, 2026
  12. romani commented on Jan 4, 2026

    @romani
    Member

    fix is merged

  13. added 2 commits that reference this issue on Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions