MissingOverrideOnRecordAccessor
Since Checkstyle 13.1.0
Description
@Override annotation.
Per JEP 395, the meaning of the
@Override annotation was extended to include explicitly declared
accessor methods for record components.
This 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.
Examples
To configure the check:
<module name="Checker">
<module name="TreeWalker">
<module name="MissingOverrideOnRecordAccessor"/>
</module>
</module>
Example:
record Person(String name, int age) {
// violation below, 'method must include @java.lang.Override annotation.'
public String name() {
return name.toUpperCase();
}
public String name(String value) {
return value;
}
@Override
public int age() {
return age;
}
public int age(int value) {
return value;
}
}
To configure the check:
<module name="Checker">
<module name="TreeWalker">
<module name="MissingOverrideOnRecordAccessor"/>
</module>
</module>
Example with record implementing interface (only record component accessors flagged):
interface Printable {
void print();
}
record Document(String title) implements Printable {
// violation below 'method must include @java.lang.Override annotation.'
public String title() {
return title.toUpperCase();
}
public void print() {
System.out.println(title);
}
}
Example of Usage
Violation Messages
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
Package
com.puppycrawl.tools.checkstyle.checks.annotation






