An Externalizable class has no public constructor without parameters, so it cannot be read back

tx0/java:externalizable-without-no-argrecommendedwarningbug

What it finds

Reading an Externalizable object starts by calling its public constructor without parameters, then readExternal. A class that declares constructors, none of them public and without parameters, cannot be read back: deserialization fails with an InvalidClassException.

From the rule's source, externalizable_without_no_arg.rs.

Example from the rule's tests
import java.io.Externalizable;import java.io.ObjectInput;import java.io.ObjectOutput; class Point implements Externalizable {tx0 reports: Point has no public constructor without parameters  int x;   Point(int x) {    this.x = x;  }   public void writeExternal(ObjectOutput out) {}   public void readExternal(ObjectInput in) {}} class Size implements Externalizable {  public Size() {}   Size(int w) {}   public void writeExternal(ObjectOutput out) {}   public void readExternal(ObjectInput in) {}}
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 from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:externalizable-without-no-arg" = "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:externalizable-without-no-arg] reason="..."

tx0 explain tx0/java:externalizable-without-no-arg shows the same in the terminal. Found a false positive? Report it.