Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving objects in servlet session and java.io.NotSerializableException

 SEVERE: IOException while loading persisted sessions:
         java.io.WriteAbortedException:
         writing aborted; java.io.NotSerializableException:

That means this object cannot be persisted on hard disk.

Does it imply that it's not safe to keep in Session objects that do not implement "Serializable"?

I haven't heard that there are limitations on saving non-serializable objects in Session object.

It simply means that Tomcat will always keep them in memory, right?

like image 931
EugeneP Avatar asked Jan 20 '26 00:01

EugeneP


1 Answers

Does it imply that it's not safe to keep in Session objects that do not implement "Serializable"?

That's exactly right, yes.

However, many servlet containers will let you get away with it, if they don't actually need to do any serialization.

For example, Tomcat doesn't care if the session attributes are serializable or not, unless you enable session replication. It needs to be able to serialize the attributes to replicate them to the other servers in the cluster.

In your case, it seems that the container is trying to persist the session data to disk, which again would require serialization.

like image 141
skaffman Avatar answered Jan 21 '26 14:01

skaffman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!