Posted By:
Randy_McLaughlin
Posted On:
Wednesday, October 17, 2001 06:54 AM
I don't believe you can reliably statically check a class to determine if everything it references is serializable.
Consider the following:
interface B {
}
class B1 implements B {
}
class B2 implements B, Serializable {
}
class A implements Serializable {
B member;
}
Statically checking class A would flag the member as unserializable. But in actual practice the member may or may not be serializable. If we have an object of class A and assign an object of class B1 to member the A object would not be serializable, but if we assign an object of class B2 to that same object it could now be serialized.
Serialization requires that all objects in the object graph are of a serializable class. That is a dynamic requirement that cannot be conclusively determined statically.
I suppose this suggests a tool that would check all classes that might be potentially referenced to determine if they are all serializable.
Why not develop a unit test to perform the test you want to make?