dcsimg
Any tools for statically checking Serializable implementation?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Monty_Zukowski
Posted On:   Tuesday, October 9, 2001 08:10 AM

Seems like I should be able to run a tool which, given a class name can walk through all the instance variables and reachable classes to let me know if I reference a class that isn't Serializable and will throw the NotSerializableException when I try. Anyone know of such a tool?

Re: Any tools for statically checking Serializable implementation?

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?

Re: Any tools for statically checking Serializable implementation?

Posted By:   AlessandroA_Garbagnati  
Posted On:   Tuesday, October 9, 2001 11:18 AM

Hi,

No I don't know any tool like that, but it doesn't look difficoult to build using reflection and instanceof.
About | Sitemap | Contact