A method has the name and arity of an inherited method but does not override it
What it finds
A method meant to override one of a superclass silently declares a new method when it does not match, and calls through the superclass keep running the old one. Two mistakes are reported, across files:
- the parameter types have the same simple names as the inherited method's but are other types, as java.sql.Date for java.util.Date or a class of the same name in another package; - the inherited method is package-private and declared in another package, so it cannot be overridden from here even though the signature matches.
Methods annotated with @Override cannot have these mistakes and compile; static and private methods are left alone, as are the hooks that serialization finds by name. Types nested in other types are not taken for an import mistake: Builder of one class and of another are usually overloads on purpose. The rule is in the recommended tier because a package-private method of the same name is sometimes shadowed on purpose.
From the rule's source, near_miss_override.rs.
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:method-misses-override" = "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:method-misses-override] reason="..."tx0 explain tx0/java:method-misses-override shows the same in the terminal. Found a false positive? Report it.