A serialVersionUID field is not static final long, so serialization ignores it

tx0/java:ignored-serial-versiondefaultwarningbug

What it finds

Serialization reads the version of a class only from a field declared exactly as static final long serialVersionUID. A field of that name that is not static, not final or not a long is ignored: the version is computed from the class's shape instead, and changes with every edit, so stored objects stop loading.

Reported in classes that name Serializable or Externalizable in their own implements clause; elsewhere the name may mean something else. Fields of interfaces are static final without saying so.

From the rule's source, ignored_serial_version.rs.

Example from the rule's tests
import java.io.Serializable; class Order implements Serializable {  private final long serialVersionUID = 1L;tx0 reports: serialVersionUID is not static, so serialization ignores it} class Item implements Serializable {  static final int serialVersionUID = 2;tx0 reports: is not of type long} class Good implements Serializable {  private static final long serialVersionUID = 3L;}
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:ignored-serial-version" = "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:ignored-serial-version] reason="..."

tx0 explain tx0/java:ignored-serial-version shows the same in the terminal. Found a false positive? Report it.