Rule Definition
Every field of a serializable class must be either serializable or transient. Declaring non-transient fields of non-serializable type inside of a serializable class will result in an exception thrown during the serialization.
Remediation
Make the field type serializable or transient.
Violation Code Sample
public static final class SomeType {}
public class SerializableField implements Serializable {
private String str;
private SomeType field; // VIOLATION
}
Fixed Code Sample
---> 1st solution
public static final class SomeType implements Serializable {} // FIXED
public class SerializableField implements Serializable {
private String str;
private SomeType field;
}
---> 2nd solution
public static final class SomeType {}
public class SerializableField implements Serializable {
private String str;
private transient SomeType field; // FIXED
}
Reference
please refer to Pattern definition of ASCRM-RLB-2: Serializable Storable Data Element without Serialization Control Element in http://www.omg.org/spec/ASCRM/1.0/PDF
Related Technologies
JEE
Technical Criterion
Programming Practices - Unexpected Behavior
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.