A writeObject, readObject or readObjectNoData method has a signature serialization does not call

tx0/java:ignored-serialization-hookdefaultwarningbug

What it finds

Serialization calls writeObject(ObjectOutputStream), readObject(ObjectInputStream) and readObjectNoData() only when they are declared private, not static, and return void. A method that looks like one of them but is public, static or returns something is never called by serialization: the class is written and read with the default format, and whatever the method was meant to do does not happen.

From the rule's source, ignored_serialization_hook.rs.

Example from the rule's tests
import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.Serializable; class Session implements Serializable {  public void writeObject(ObjectOutputStream out) throws IOException {tx0 reports: serialization never calls this writeObject: it is not private    out.defaultWriteObject();  }   private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {    in.defaultReadObject();  }   private static void readObjectNoData() {}tx0 reports: it is static   public void writeObject(String other) {}}
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-serialization-hook" = "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-serialization-hook] reason="..."

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