[jboss-jira] [JBoss JIRA] Commented: (JASSIST-42) Proxy serialization looses inner data objects
David Lloyd (JIRA)
jira-events at lists.jboss.org
Tue Nov 10 01:03:06 EST 2009
[ https://jira.jboss.org/jira/browse/JASSIST-42?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12493916#action_12493916 ]
David Lloyd commented on JASSIST-42:
------------------------------------
This is indeed a very nefarious problem, however it is not unsolvable. You could solve it in a couple of ways:
1) The logic that serialization implements is well-defined; you could continue to use a serialized proxy via writeReplace; however, on the write side, use reflection to store all superclass field values into an array in the proxy, duplicating the logic of Java Serialization. On the read side, the readResolve of the serialized proxy object would then use the same sun.reflect.ReflectionFactory that Java Serialization uses to create new instances, and then would use reflection to populate all the fields, exactly as ObjectInputStream would. The disadvantage is that any field value which refers to an object which refers back to the original proxy will have an invalid reference, and would cause an exception on deserialization; and of course, this represents a fairly substantial coding effort besides.
2) Require the use of special class annotation/resolver logic by way of java.io.ObjectOutputStream#annotateClass() and java.io.ObjectInputStream#resolveClass(). The logic in annotateClass() would write out an identifying byte marking the class as a Javassist proxy, followed by the superclass and the list of the proxy's implemented interfaces. The logic in resolveClass() would read this data and use the ProxyFactory's createClass() method to get the (possibly cached) class object if it is present. Then, the proxy need only implement Serializable or Externalizable, like any object, and everything will work perfectly in all cases; the solution is essentially bulletproof, apart from the disadvantage of requiring the customized subclasses. This could, however, be easily accomplished by way of a pair of static methods in a utility class, so the burden to the user should be minimal compared to the gain.
> Proxy serialization looses inner data objects
> ---------------------------------------------
>
> Key: JASSIST-42
> URL: https://jira.jboss.org/jira/browse/JASSIST-42
> Project: Javassist
> Issue Type: Bug
> Reporter: Damien Lecan
> Assignee: Shigeru Chiba
> Priority: Blocker
>
> I working with proxies build with ProxyFactory method.
> When I want to serialize/deserialize it, everything seems to be ok except that only proxy instance is serialized, not inner objects.
> Eg.
> Object "A" contains an instance of "B"
> After serialization/deserialization of a proxy of A, instance of "B" in "A" is null
> When I look at this code :
> public static SerializedProxy makeSerializedProxy(Object proxy)
> throws java.io.InvalidClassException
> {
> Class clazz = proxy.getClass();
> return new SerializedProxy(clazz, ProxyFactory.getFilter(clazz),
> ProxyFactory.getHandler(clazz));
> }
> I don't understand how serialization can keep inner objects ...
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list