CompareTo takes another type than the class compares itself with, so Comparable never calls it
What it finds
A class that implements Comparable<Version> must define compareTo(Version). A method compareTo(String) next to it is an overload that sorting and sorted collections never call, since they go through the interface; usually it was meant to be the implementation and the parameter type is wrong.
Reported is a compareTo with one parameter whose type is neither the type argument of the class's Comparable nor Object.
From the rule's source, compare_to_overload.rs.
class Version implements Comparable<Version> { public int compareTo(Version other) { return 0; } public int compareTo(String other) {tx0 reports: does not take Version return 0; }} 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:compare-to-wrong-type" = "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:compare-to-wrong-type] reason="..."tx0 explain tx0/java:compare-to-wrong-type shows the same in the terminal. Found a false positive? Report it.