extracting the only serialversionuid from a stream
Hello all,
I know some naughty little programmers who serialized an object (really multiple objects) and stored it to a database in a production system. Unfortunately, they did not define serialVersionUID's for their classes and thus we are getting exceptions saying the UID's don't match. I assure you all that the classes are still indeed compatible in terms of any changes made.
In trying to solve this problem, I think the "easiest" way is to figure out what the stored serialVersionUID field is, and then paste that into our source code. One way to do this would be to enter in a random uid and check the exception text, which will tell the stored vs. the calculated uid. That however is tedious.
An only slightly better idea I came up with was to do something like this pseudo code:
foreach (array of bytes arr : from database){
//MyObjectInputStream extends ObjectInputStream, simply
//making public the readClassDescriptor() function
MyObjectInputStream stream =new
MyObjectInputStream(new ByteArrayInputStream(arr));
//this function simply runs through the array looking for this constant
int pos = find(arr, ObjectStreamConstants.TS_CLASDESC);
stream.skip(pos + 1);
stream.readClassDescriptor();
long suid = stream.getSuid()//or whatever the actual function is
return suid;
}
When I implemented this, I got an EOFException when calling readClassDescriptor.
I'm not exactly sure where the bug is, but my first question to you all is, is there anything obviously wrong with this approach?
Secondly, is there a better way (other than beating the developers who forgot to define their UID's) to go about this that I am completely missing?
Thanks in advance!!
Justin

