A value matched by a type pattern of a record is used only to call its accessors, which a record pattern would bind directly
What it finds
if (o instanceof Point p) return p.x() + p.y(); binds the record only to take it apart. A record pattern, o instanceof Point(int x, int y), binds the components.
Reported is a type pattern of a record declared in the file whose variable is used at least once and only as the receiver of calls of the record's accessors.
From the rule's source, record_pattern_candidate.rs.
record Point(int x, int y) {} class Patterns { int run(Object o) { if (o instanceof Point p) {tx0 reports: only taken apart return p.x() + p.y(); } if (o instanceof Point q) { return q.hashCode(); } if (o instanceof String s) { return s.length(); } return 0; }} 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:
[rules]
"tx0/java:record-pattern-candidate" = "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-pattern-candidate] reason="..."tx0 explain tx0/java:record-pattern-candidate shows the same in the terminal. Found a false positive? Report it.