yonatan
yonatan

Reputation: 187

serialization check - compile time and runtime

i am looking for a tool, that can tell me whether a class / object is legal serializeable object (implements serializable, and all its fields are serializable). i know that i can know whether an object is serializable only on run time. i want to get warning on compile time, whether a class can be not serializable (e.g - a member is not serializeable, although in runtime it can be null, or of seriazliable sub class type). in addition, on runtime i want to check if a class is really serializable, before trying to send it over the network as a serialized object.

thanks...

Upvotes: 1

Views: 1573

Answers (2)

Joeri Hendrickx
Joeri Hendrickx

Reputation: 17435

This is usually done using static code analysis.

One tool that's used a lot is Findbugs. It will tell you about many common problems and suspect behaviour. One of its checks is the one you mention (described here).

There are plugins for most IDEs for this, so it can do its job while you work, and a common pattern is to include this in your automatic build.

Upvotes: 1

jkraybill
jkraybill

Reputation: 3399

Does it have to be compile time? I've done this with unit tests before, which is pretty close to compile time in terms of development lifecycle. This article is a bit dated but outlines a few good approaches. We also caught unserializable state by doing a true failover test for our webapp using two web servers, which is why I needed to verify serializability.

Upvotes: 4

Related Questions