[jboss-jira] [JBoss JIRA] (JBSER-113) Caching of replaced objects doesn't conform to Java serialization specification

Ron Sigal (JIRA) issues at jboss.org
Wed Jun 20 18:35:00 EDT 2018


     [ https://issues.jboss.org/browse/JBSER-113?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ron Sigal closed JBSER-113.
---------------------------
    Resolution: Out of Date


> Caching of replaced objects doesn't conform to Java serialization specification
> -------------------------------------------------------------------------------
>
>                 Key: JBSER-113
>                 URL: https://issues.jboss.org/browse/JBSER-113
>             Project: JBoss Serialization
>          Issue Type: Bug
>    Affects Versions: 1.0.3 GA
>            Reporter: Ron Sigal
>            Assignee: Ron Sigal
>             Fix For: 1.1.0 Beta
>
>
> The Java serialization spec gives the following steps in serialization:
>     4. If the object has been previously replaced, as described in Step 8, write the handle of the replacement to the stream and writeObject returns.
>         ...
>     8. a. ....
>         b. ...
>         If the original object was replaced by either one or both steps above, the mapping from the original object to the replacement is recorded for later use in Step 4. Then, Steps 3 through 7 are repeated on the new object.
> But JBossSerialization does this:
>     * Apply all the replacements
>     * If the replacement object has already been written, write its "handle".
> I used to think this was just an efficiency issue (why do the replacement code on an object the second time it gets processed), but one of the JBossMarshalling tests shows that there is an actual semantic difference:
>     ArrayList<Object> testList = new ArrayList<Object>();      
>     testList = Collections.unmodifiableList(testList);
>     marshaller.writeObject(testList);
>     marshaller.writeObject(testList);
>     assertSame(unmarshaller.readObject(), unmarshaller.readObject());
> The assertion will fail with JBossSerialization because Collections.unmodifiableList() returns an instance of
>     static class UnmodifiableRandomAccessList<E> extends UnmodifiableList<E> implements RandomAccess {
>         private Object writeReplace() {
>             return new UnmodifiableList<E>(list);
>         }
>     }
> JBossSerialization applies UnmodifiableRandomAccessList.writeReplace() during each call to marshaller.writeObject(), so two different copies of testList get written.  But in Java serialization, the second call would see that the object has already been written and a handle would get written.



--
This message was sent by Atlassian JIRA
(v7.5.0#75005)


More information about the jboss-jira mailing list