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

Ron Sigal (JIRA) jira-events at lists.jboss.org
Wed Mar 18 22:48:22 EDT 2009


Caching of replaced objects doesn't conform to Java serialization specification
-------------------------------------------------------------------------------

                 Key: JBSER-113
                 URL: https://jira.jboss.org/jira/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 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