A serializable class leaves its stream version to be computed from its shape
What it finds
A class that implements Serializable without a serialVersionUID gets a version computed from its fields and methods. Adding a method or recompiling with another compiler can change it, and objects stored or sent before then fail to load with an InvalidClassException. A declared version changes only when it is changed on purpose.
Reported for classes that name Serializable in their own implements clause.
From the rule's source, missing_serial_version.rs.
import java.io.Serializable; class Order implements Serializable {tx0 reports: Order is serializable but declares no serialVersionUID int id;} class Item implements Serializable { private static final long serialVersionUID = 1L;} class Plain { int id;} 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:missing-serial-version" = "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:missing-serial-version] reason="..."tx0 explain tx0/java:missing-serial-version shows the same in the terminal. Found a false positive? Report it.