A final class only holds private final fields set by its constructor and read by getters, which a record declares in one line

tx0/java:data-class-as-recordstrictwarningstyle/conventionsdepth faststyle

What it finds

A class whose fields are all private and final, set once by a constructor and read by getters, is what a record is. The record also gets equals, hashCode and toString that follow its fields, which hand-written ones easily stop doing.

Reported is a final class without annotations or supertypes, with at least one instance field, all of them private final without initializer, one constructor that takes as many parameters as there are fields, and no methods other than getters without parameters and equals, hashCode and toString.

From the rule's source, data_class_as_record.rs.

Example from the rule's tests
final class Point {tx0 reports: only carries data  private final int x;  private final int y;  Point(int x, int y) {    this.x = x;    this.y = y;  }  int x() {    return x;  }  public String toString() {    return x + "," + y;  }}final class Counter {  private int count;  Counter(int count) {    this.count = count;  }  void add() {    count++;  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:data-class-as-record" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/java:data-class-as-record] reason="..."

tx0 explain tx0/java:data-class-as-record shows the same in the terminal. Found a false positive? Report it.