Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 34015 invoked from network); 15 Jul 2005 18:34:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 15 Jul 2005 18:34:11 -0000 Received: (qmail 67682 invoked by uid 500); 15 Jul 2005 18:34:07 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 67613 invoked by uid 500); 15 Jul 2005 18:34:07 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 67598 invoked by uid 99); 15 Jul 2005 18:34:06 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Jul 2005 11:34:06 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=RCVD_BY_IP,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of davanum@gmail.com designates 64.233.170.198 as permitted sender) Received: from [64.233.170.198] (HELO rproxy.gmail.com) (64.233.170.198) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Jul 2005 11:34:01 -0700 Received: by rproxy.gmail.com with SMTP id 40so369938rnz for ; Fri, 15 Jul 2005 11:34:02 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=eQ3LEUfvWobRC7iS9dO765WrcgCb9RDeTkhamDN5Js9+L7Y6y8Vm2jhOfggG4NZ9eXT70yEncGAMawskEsEf7dDB5hR769O2tLQRgVY80fhPY8B4HuhjmGCtHScB02kTyUyqZYqMhBLC+Lnge5XXx3TEVVFNfbvGbBXUXMPbFno= Received: by 10.38.8.11 with SMTP id 11mr170662rnh; Fri, 15 Jul 2005 11:33:58 -0700 (PDT) Received: by 10.38.8.28 with HTTP; Fri, 15 Jul 2005 11:33:58 -0700 (PDT) Message-ID: <19e0530f0507151133516c52b7@mail.gmail.com> Date: Fri, 15 Jul 2005 14:33:58 -0400 From: Davanum Srinivas Reply-To: dims@apache.org To: Jakarta Commons Developers List Subject: Re: UnboundedFifoBuffer - serialization bug + fix In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Applied to SVN. thanks. -- dims On 7/15/05, Knych, Thomas [IT] wrote: > Dims - >=20 > The patch should be: >=20 > private void readObject(ObjectInputStream in) throws IOException, ClassNo= tFoundException { > in.defaultReadObject(); > int size =3D in.readInt(); > - buffer =3D new Object[size]; > + buffer =3D new Object[size + 1]; > for (int i =3D 0; i < size; i++) { > buffer[i] =3D in.readObject(); > } > head =3D 0; > tail =3D size; > } >=20 >=20 >=20 > Setting tail =3D size - 1; just caused another bug (ie you couldn't get t= he last element in the buffer). This is because tail is supposed to point t= o the next unused cell in the buffer array. By creating the buffer to be si= ze + 1, tail will be set to a valid cell within buffer that is empty (but t= he cell before it has an element in it), and the class works properly. >=20 > Thanks, >=20 > -TK >=20 >=20 > -----Original Message----- > From: Davanum Srinivas [mailto:davanum@gmail.com] > Sent: Thursday, July 14, 2005 8:26 AM > To: Jakarta Commons Developers List > Cc: Knych, Thomas [IT]; *GT GFI ALF Development > Subject: Re: UnboundedFifoBuffer - serialization bug + fix >=20 >=20 > Jordan, >=20 > So the patch is the one-liner in previous email? ("tail =3D size - 1;"?) >=20 > -- dims >=20 > On 7/13/05, Krey, Jordan [IT] wrote: > > 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 IOExceptio= n, ClassNotFoundException { > > 124 in.defaultReadObject(); > > 125 int size =3D in.readInt(); > > 126 buffer =3D new Object[size + 1]; <-- must be size + 1 i= n order to satisfy the condition of Iterator.hasNext() > > 127 for (int i =3D 0; i < size; i++) { > > 128 buffer[i] =3D in.readObject(); > > 129 } > > 130 head =3D 0; > > 131 tail =3D size; > > 132 } > > > > For example, previously, if size =3D=3D 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 >=3D buffer.length) { <-- buffer length =3D= =3D 1 > > 249 index =3D 0; <-- index now= set back to 0 > > 250 } > > 251 return index; > > 252 } > > > > 279 public boolean hasNext() { > > 280 return index !=3D tail; <-- index =3D=3D 0, t= ail =3D=3D 1 > > 281 > > 282 } > > > > Now: > > 246 private int increment(int index) { > > 247 index++; > > 248 if (index >=3D buffer.length) { <-- buffer length =3D= =3D 2 > > 249 index =3D 0; > > 250 } > > 251 return index; <-- index =3D= =3D 1 > > 252 } > > > > 279 public boolean hasNext() { > > 280 return index !=3D tail; <-- index =3D=3D 1, t= ail =3D=3D 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. Ap= parently when the object is serialized and then read back in the tail varia= ble 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 ot= her 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/or= g/apache/commons/collections/buffer/UnboundedFifoBuffer.java 2005-07-13 1= 0: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] =3D in.readObject(); > > } > > head =3D 0; > > - tail =3D size; > > + tail =3D size - 1; > > } > > > > //----------------------------------------------------------------= ------- > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > > For additional commands, e-mail: commons-dev-help@jakarta.apache.org > > > > >=20 >=20 > -- > Davanum Srinivas -http://blogs.cocoondev.org/dims/ >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > For additional commands, e-mail: commons-dev-help@jakarta.apache.org >=20 >=20 --=20 Davanum Srinivas -http://blogs.cocoondev.org/dims/ --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org