Today I have came across strange behavior in java serialization and deserialization("strange" because I don't understand)
I was serializing and deserializing an object from a linux shared directory.
While serializing everything worked without any problem, but when I tried to deserialize the same file it throws
java. io. EOFException
. Also deserializing was only failing for this newly created file and was working for all other old files in that directory.
So I searched across internet and found one thread which said Low disk space can also be cause of this error.
So I cleaned up some temp files and voila it worked. I do not understand how low disk space can only affect deserialization and not serialization?
I am using apache commons SerializationUtils
class. Below is the code for serialization and deserialization
SerializationUtils. serialize(myObject, new FileOutputStream(new File(sharePath+FILEName) ;
MyObject object=SerializationUtils. deserialize( new FileInputStream(new File(sharePath+FILEName);
It would be really helpful if someone can explain this behavior. I suspect its a bug in SerializationUtils maybe gobbling up IOException.
Thanks
My suspicion is that when writing the file, an ioexception is being thrown because the disk space has run out, but the beginning of the serialized data was still written to disk. This would mean that the serialized data stored on the disk is incomplete, so reading it would give invalid results, which in your case is causing an EOF Exception
In order to solve this problem, you need to see when the IO exception is thrown due to the disk space running out with exception.getMessage()
and make sure not to write incomplete data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With