Uploaded image for project: 'Commons Collections'
  1. Commons Collections
  2. COLLECTIONS-220

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.2
    • None
    • Buffer
    • None

    Description

      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.

      Attachments

        1. ASF.LICENSE.NOT.GRANTED--SerializationTest.java
          4 kB
          Jose Luis Huertas
        2. COLLECTIONS-200.patch
          1 kB
          Dave Meikle
        3. COLLECTIONS-220.patch
          3 kB
          Henri Yandell

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jlhuertas Jose Luis Huertas
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: