A class implements Cloneable but does not override clone()
What it finds
Cloneable only permits Object.clone(), which stays protected; without a public clone() override, code outside the class cannot copy the object, and the shallow copy Object.clone makes may share mutable fields, as the Cloneable documentation explains.
Reported is a class that implements Cloneable, extends no other class from which it could inherit a clone(), and declares none.
From the rule's source, cloneable_without_clone.rs.
class Sheep implements Cloneable {}tx0 reports: does not override clone() class Goat implements Cloneable { @Override public Goat clone() throws CloneNotSupportedException { return (Goat) super.clone(); }} 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:cloneable-without-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:cloneable-without-override] reason="..."tx0 explain tx0/java:cloneable-without-override shows the same in the terminal. Found a false positive? Report it.