Wednesday, October 31, 2007

Java Serialization Debugging

Today I had a fight with Java as I was inadvertently trying to serialize something that was not serializable. The object being serialized had a crapload of fields, which in turn, all had craploads of other fields so I pretty much had no idea what was causing the incredibly uninformative "Exception in thread "main" java.io.NotSerializableException." So after spending an hour trying to write a function to reflectively traverse the object tree in search of non-serializable fields, I found this helpful piece. The DebuggingObjectOutputStream is nice, but the comments have something even more simple and helpful: set the vm parameter sun.io.serialization.extendedDebugInfo=true, and voila, helpful stack traces to find what object is actually causing the serialization errors!

No comments: