You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Jose Luis Huertas (JIRA)" <ji...@apache.org> on 2006/08/07 15:55:13 UTC

[jira] Created: (COLLECTIONS-220) Serialization/Deserialization doesn't work well with empty buffers.

Serialization/Deserialization doesn't work well with empty buffers.
-------------------------------------------------------------------

                 Key: COLLECTIONS-220
                 URL: http://issues.apache.org/jira/browse/COLLECTIONS-220
             Project: Commons Collections
          Issue Type: Bug
          Components: Buffer
    Affects Versions: 3.2
            Reporter: Jose Luis Huertas
            Priority: Minor
         Attachments: SerializationTest.java

When I serialize the queue to disk an it has elements, all works ok, but when I serialize an empty queue I have some problems when I create a new object using the serialized file.

When I deserialize the queue it has a 'buffer' with size 1 (with null content), 'tail' and 'head' fields are 0 (they are declared transient). So, when I try to add a new object to the queue, the sentence:

 Object[] tmp = new Object[((buffer.length - 1) * 2) + 1];

Is executed in the add() method to increase the buffer length, but the buffer remains with the same size! (buffer.length = 1 --> (1 - 1) * 2 + 1 = 1). So, the object is added and when the tail is going to be incremented, it is reset to 0!! 

    private int increment(int index) {
        index++;
        if (index >= buffer.length) {
            index = 0;
        }
        return index;
    }


So it is impossible to add new elements after an empty queue has been serialized / deserialized.

I attach a simple TestCase where this is proved. The example works when you use XMLEncoder to serialize the buffer but doesn't work if you use ObjectOutputStream or XStream.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Updated: (COLLECTIONS-220) Serialization/Deserialization doesn't work well with empty buffers.

Posted by "Dave Meikle (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/COLLECTIONS-220?page=all ]

Dave Meikle updated COLLECTIONS-220:
------------------------------------

    Attachment: COLLECTIONS-200.patch

Proposed Patch to fix Object Serialization Problem

> Serialization/Deserialization doesn't work well with empty buffers.
> -------------------------------------------------------------------
>
>                 Key: COLLECTIONS-220
>                 URL: http://issues.apache.org/jira/browse/COLLECTIONS-220
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Buffer
>    Affects Versions: 3.2
>            Reporter: Jose Luis Huertas
>            Priority: Minor
>         Attachments: COLLECTIONS-200.patch, SerializationTest.java
>
>
> When I serialize the queue to disk an it has elements, all works ok, but when I serialize an empty queue I have some problems when I create a new object using the serialized file.
> When I deserialize the queue it has a 'buffer' with size 1 (with null content), 'tail' and 'head' fields are 0 (they are declared transient). So, when I try to add a new object to the queue, the sentence:
>  Object[] tmp = new Object[((buffer.length - 1) * 2) + 1];
> Is executed in the add() method to increase the buffer length, but the buffer remains with the same size! (buffer.length = 1 --> (1 - 1) * 2 + 1 = 1). So, the object is added and when the tail is going to be incremented, it is reset to 0!! 
>     private int increment(int index) {
>         index++;
>         if (index >= buffer.length) {
>             index = 0;
>         }
>         return index;
>     }
> So it is impossible to add new elements after an empty queue has been serialized / deserialized.
> I attach a simple TestCase where this is proved. The example works when you use XMLEncoder to serialize the buffer but doesn't work if you use ObjectOutputStream or XStream.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Updated: (COLLECTIONS-220) Serialization/Deserialization doesn't work well with empty buffers.

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/COLLECTIONS-220?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated COLLECTIONS-220:
--------------------------------------

    Fix Version/s: 3.3

Nice simple patch. +1. 

> Serialization/Deserialization doesn't work well with empty buffers.
> -------------------------------------------------------------------
>
>                 Key: COLLECTIONS-220
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-220
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Buffer
>    Affects Versions: 3.2
>            Reporter: Jose Luis Huertas
>            Priority: Minor
>             Fix For: 3.3
>
>         Attachments: COLLECTIONS-200.patch, SerializationTest.java
>
>
> When I serialize the queue to disk an it has elements, all works ok, but when I serialize an empty queue I have some problems when I create a new object using the serialized file.
> When I deserialize the queue it has a 'buffer' with size 1 (with null content), 'tail' and 'head' fields are 0 (they are declared transient). So, when I try to add a new object to the queue, the sentence:
>  Object[] tmp = new Object[((buffer.length - 1) * 2) + 1];
> Is executed in the add() method to increase the buffer length, but the buffer remains with the same size! (buffer.length = 1 --> (1 - 1) * 2 + 1 = 1). So, the object is added and when the tail is going to be incremented, it is reset to 0!! 
>     private int increment(int index) {
>         index++;
>         if (index >= buffer.length) {
>             index = 0;
>         }
>         return index;
>     }
> So it is impossible to add new elements after an empty queue has been serialized / deserialized.
> I attach a simple TestCase where this is proved. The example works when you use XMLEncoder to serialize the buffer but doesn't work if you use ObjectOutputStream or XStream.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org