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
Following discussion in #17561,
Problem:
There is currently no check that verifies the presence of
@Overrideon explicitly declared record component accessor methods.Per JEP 395, the meaning of the
@Overrideannotation was extended to include explicitly declared accessor methods for record components.Proposed Check
Name:
MissingOverrideOnRecordAccessorDetection Logic:
RECORD_DEF@OverrideExample (violation):
Example (valid):
Scope