[jboss-dev-forums] [Design of JBossCache] - Re: Incorrect serialization of PojoCache collection class pr

bstansberry@jboss.com do-not-reply at jboss.com
Thu Nov 2 22:55:47 EST 2006


This can easily happen -- a pojo with a collection field gets put in the cache, and then some user code hands a ref to the collection to some other object, that object gets serialized (say as part of a response to a remote call); boom!

The case on the other forum post is a bit odd, as the serialization there is occuring due to cache replication itself.  That's kind of a bad practice; they should aspectize all their classes.  But I think we need to support the generic case where a Collection gotten from the cache gets serialized.

But, I don't think there's any need at all to try to maintain any object relationship or anything when the object is deserialized.  So, this kind of thing should work fine:

Example is CachedListImpl:

  | private Object writeReplace()  throws ObjectStreamException {
  |    ArrayList toSerialize = new ArrayList();
  |    toSerialize.addAll(this);
  |    return toSerialize;
  | }
  | 
toSerialize is what gets serialized.  When deserialized, it's a List, as expected. If the user thought the deserialized list would somehow be the same object as something stored in a PojoCache somewhere (where???), they're not thinking right.
    



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3982846#3982846

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3982846



More information about the jboss-dev-forums mailing list