A serializable inner class is not static, so serializing it also serializes its outer object
What it finds
An inner class that is not static holds a hidden reference to its outer object, and serialization follows it. When the outer class is not serializable, writing the inner object throws a NotSerializableException; when it is, the whole outer object is written along. The java.io.Serializable documentation and the serialization specification advise against serializing inner classes for this reason.
Reported is a member class that implements Serializable, is not static, and is declared in a class.
From the rule's source, serializable_inner_class.rs.
import java.io.Serializable; class Outer { class Inner implements Serializable {}tx0 reports: serializing this inner class fails static class Nested implements Serializable {}} class Holder implements Serializable { class Part implements Serializable {}tx0 reports: drags its outer object} 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:serializable-inner-class" = "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:serializable-inner-class] reason="..."tx0 explain tx0/java:serializable-inner-class shows the same in the terminal. Found a false positive? Report it.