race in org.beepcore.beep.lib.Reply

Lawrence Greenfield <[email protected]> Fri, 13 Jun 2003 14:34:10 -0400
Newsgroups gmane.network.beep.beepcore.java.general
Message-ID <[email protected]>
--Multipart_Fri_Jun_13_14:34:10_2003-1
Content-Type: text/plain; charset=US-ASCII

The Reply class has a pretty serious race condition in it: hasNext()
fails to check the pending replies after coming off of the wait().

Patch attached. My patch also inserts a while() loop around the
wait(), which is generally good form.

Larry


--Multipart_Fri_Jun_13_14:34:10_2003-1
Content-Type: application/octet-stream; type=patch
Content-Disposition: attachment; filename="reply.patch"
Content-Transfer-Encoding: 7bit

--- src/org/beepcore/beep/lib/Reply.java	Wed Apr 23 11:23:02 2003
+++ /tmp/MyReply.java	Fri Jun 13 14:26:47 2003
@@ -109,25 +109,15 @@
      */
     synchronized public boolean hasNext() throws BEEPInterruptedException
     {
-        if (this.replies.size() != 0) {
-            return true;
-        }
-
-        if (this.complete) {
-            return false;
-        }
-
         try {
-            this.wait();
+            while (replies.size() == 0 && !complete) {
+                this.wait();
+            }
         } catch (InterruptedException x) {
             throw new BEEPInterruptedException(x.getMessage());
         }
 
-        if (complete) {
-            return false;
-        }
-
-        return true;
+        return replies.size() > 0;
     }
 
     private synchronized void setMessage(Message message)

--Multipart_Fri_Jun_13_14:34:10_2003-1--



-------------------------------------------------------
This SF.NET email is sponsored by: eBay
Great deals on office technology -- on eBay now! Click here:
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5