A method named like hashCode, toString or equals but spelled differently

tx0/java:misspelled-object-methoddefaultwarningbug

What it finds

public int hashcode(), public String tostring() and public boolean equal(Object o) look like the methods of Object but do not override them, because of the spelling. The class keeps the inherited behavior, and the method is called only where it is called by name.

The return and parameter types must be those of the method of Object.

From the rule's source, misspelled_object_method.rs.

Example from the rule's tests
class Money {  long cents;   public int hashcode() {tx0 reports: hashcode does not override hashCode    return (int) cents;  }   public String tostring() {tx0 reports: tostring does not override toString    return "" + cents;  }   public boolean equal(Object o) {tx0 reports: equal does not override equals    return o == this;  }   public boolean equal(Money other) {    return other.cents == cents;  }   public long hashcode(int seed) {    return seed;  }}
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 in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/java:misspelled-object-method" = "off"

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:misspelled-object-method] reason="..."

tx0 explain tx0/java:misspelled-object-method shows the same in the terminal. Found a false positive? Report it.