ReadResolve of a class that can be extended is private, so subclasses do not inherit it
What it finds
Serialization calls readResolve on the class of the object read, including methods it inherits, but a private one is not inherited: an instance of a subclass is not resolved, and a singleton gets a second instance. The serialization specification suggests protected for classes that can be extended.
Reported is a private readResolve() in a class that is not final.
From the rule's source, private_read_resolve.rs.
import java.io.Serializable; class Singleton implements Serializable { private Object readResolve() {tx0 reports: not inherited by subclasses return this; }} final class Sealed implements Serializable { private Object readResolve() { return this; }} 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:private-read-resolve" = "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:private-read-resolve] reason="..."tx0 explain tx0/java:private-read-resolve shows the same in the terminal. Found a false positive? Report it.