A record holds an array, which its generated equals and hashCode compare by identity
What it finds
The equals and hashCode a record gets compare its components with their own equals and hashCode, which for an array means identity: two records holding arrays with the same elements are not equal, and land in different buckets of a hash map. Overriding both methods with Arrays.equals and Arrays.hashCode, or holding a List, compares the contents.
Reported are array components of records that override neither equals nor hashCode.
From the rule's source, record_array_component.rs.
record Packet(String name, byte[] payload) {}tx0 reports: the array payload is compared by identity record Point(int x, int y) {} record Safe(int[] values) { @Override public boolean equals(Object o) { return o instanceof Safe s && java.util.Arrays.equals(values, s.values); } @Override public int hashCode() { return java.util.Arrays.hashCode(values); }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:record-array-component" = "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:record-array-component] reason="..."tx0 explain tx0/java:record-array-component shows the same in the terminal. Found a false positive? Report it.