commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Krey, Jordan [IT]" <jordan.k...@citigroup.com>
Subject RE: UnboundedFifoBuffer - serialization bug + fix
Date Wed, 13 Jul 2005 15:58:56 GMT
Commons Collections-

Correction.

116     /***
117      * Read the buffer in using a custom routine.
118      * 
119      * @param in  the input stream
120      * @throws IOException
121      * @throws ClassNotFoundException
122      */
123     private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
{
124         in.defaultReadObject();
125         int size = in.readInt();
126         buffer = new Object[size + 1];     <-- must be size + 1 in order to satisfy
the condition of Iterator.hasNext()
127         for (int i = 0; i < size; i++) {
128             buffer[i] = in.readObject();
129         }
130         head = 0;
131         tail = size;
132     }

For example, previously, if size == 1 and the object was read in.  The next iteration would
fail at the increment() and hasNext() methods:
246     private int increment(int index) {
247         index++;
248         if (index >= buffer.length) {  	<-- buffer length == 1
249             index = 0;				<-- index now set back to 0			
250         }
251         return index;
252     }

279             public boolean hasNext() {
280                 return index != tail; 	<-- index == 0, tail == 1
281 
282             }

Now:
246     private int increment(int index) {
247         index++;
248         if (index >= buffer.length) {  	<-- buffer length == 2
249             index = 0;						
250         }
251         return index;				<-- index == 1
252     }

279             public boolean hasNext() {
280                 return index != tail; 	<-- index == 1, tail == 1
281 
282             }

-Jordan & Citigroup Analytics Dev team


-----Original Message-----
From: Knych, Thomas [IT] 
Sent: Wednesday, July 13, 2005 10:15 AM
To: 'commons-dev@jakarta.apache.org'
Cc: *GT GFI ALF Development
Subject: UnboundedFifoBuffer - serialization bug + fix


Commons Collections- 

We recently found a bug in the serialization of UnboundedFifoBuffer. Apparently when the object
is serialized and then read back in the tail variable is set to size; it should actually be
set to size - 1 because otherwise the tail element will be beyond the bounds of the internal
array. Among other things this will cause the iterator to infinitely loop.


Attached is our own local patch...

Thanks!

-TK & Citigroup Analytics Dev team




--- /home/tk53899/tmp/commons-colls/commons-collections-3.1/src/java/org/apache/commons/collections/buffer/UnboundedFifoBuffer.java
  2005-07-13 10:08:12.000000000 -0400
+++ org/apache/commons/collections/buffer/UnboundedFifoBuffer.java      2005-07-13 10:01:56.000000000
-0400
@@ -50,7 +50,7 @@
  * This class is Serializable from Commons Collections 3.1.
  *
  * @since Commons Collections 3.0 (previously in main package v2.1)
- * @version $Revision: 1.9 $ $Date: 2004/06/01 22:57:18 $
+ * @version $Revision: 1.1.2.1 $ $Date: 2005/07/13 14:01:56 $
  *
  * @author Avalon
  * @author Federico Barbieri
@@ -128,7 +128,7 @@
             buffer[i] = in.readObject();
         }
         head = 0;
-        tail = size;
+        tail = size - 1;
     }

     //-----------------------------------------------------------------------

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


Mime
View raw message