Skip to content

New check: MissingOverrideOnRecordAccessor to require Override on record component accessor methods #18368

@vivek-0509

Description

@vivek-0509

Following discussion in #17561,

Problem:

There is currently no check that verifies the presence of @Override on explicitly declared record component accessor methods.

Per JEP 395, the meaning of the @Override annotation was extended to include explicitly declared accessor methods for record components.

Proposed Check

Name: MissingOverrideOnRecordAccessor

Detection Logic:

  • Method inside RECORD_DEF
  • Zero parameters
  • Method name matches record component
  • Missing @Override

Example (violation):

record Person(String name) {
    public String name() {
        return name.toUpperCase();
    }
}

Example (valid):

record Person(String name) {
    @Override
    public String name() {
        return name.toUpperCase();
    }
}

Scope

  • The check focuses only on record component accessor methods
  • It does not attempt to detect general method overrides from interfaces or superclasses, due to Checkstyle’s single file analysis limitations

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