commits@javamail.java.net

[mercurial:74] Fix synchronization of response handlers list - Bug GF 3929

From: <shannon_at_kenai.com>
Date: Tue, 11 Nov 2008 01:05:05 +0000 (GMT)

Repository: mercurial
Revision: 74
Author: Bill Shannon <bill.shannon_at_sun.com>
Date: 2008-08-18 23:02:06 UTC

Log Message:
-----------
Fix synchronization of response handlers list - Bug GF 3929

Modified Paths:
--------------
    doc/release/CHANGES.txt
    mail/src/main/java/com/sun/mail/iap/Protocol.java

Diffs:
-----
diff -r 5b9ce0e68dfe -r 47fa61b3ac79 doc/release/CHANGES.txt
--- a/doc/release/CHANGES.txt Thu Aug 07 14:35:08 2008 -0700
+++ b/doc/release/CHANGES.txt Mon Aug 18 16:02:06 2008 -0700
@@ -25,6 +25,7 @@
 6720896 add mail.mime.uudecode.ignoreerrors system property
 6720896 add mail.mime.uudecode.ignoremissingbeginend system
property
 6730637 deadlock when mail.imap.connectionpoolsize greater than
1
+GF 3929 Inconsistent synchronization in
com.sun.mail.iap.Protocol
 GF 4997 BASE64DecoderStream.skip (etc) skips the wrong number
of octets
 GF 5189 Can't specify SSLSocketFactory for STARTTLS in Javamail
1.4
 <no id> ignore socket timeout while waiting in IMAP IDLE
diff -r 5b9ce0e68dfe -r 47fa61b3ac79
mail/src/main/java/com/sun/mail/iap/Protocol.java
--- a/mail/src/main/java/com/sun/mail/iap/Protocol.java Thu Aug 07
14:35:08 2008 -0700
+++ b/mail/src/main/java/com/sun/mail/iap/Protocol.java Mon Aug 18
16:02:06 2008 -0700
@@ -71,7 +71,12 @@
 
     private int tagCounter = 0;
 
- private volatile Vector handlers = null; // response handlers
+ /*
+ * handlers is a Vector, initialized here,
+ * because we depend on it always existing and depend
+ * on the synchronization that Vector provides.
+ */
+ private volatile Vector handlers = new Vector(); // response
handlers
 
     private volatile long timestamp;
 
@@ -170,25 +175,22 @@
     /**
      * Adds a response handler.
      */
- public synchronized void addResponseHandler(ResponseHandler h) {
- if (handlers == null)
- handlers = new Vector();
+ public void addResponseHandler(ResponseHandler h) {
        handlers.addElement(h);
     }
 
     /**
      * Removed the specified response handler.
      */
- public synchronized void removeResponseHandler(ResponseHandler h)
{
- if (handlers != null)
- handlers.removeElement(h);
+ public void removeResponseHandler(ResponseHandler h) {
+ handlers.removeElement(h);
     }
 
     /**
      * Notify response handlers
      */
     public void notifyResponseHandlers(Response[] responses) {
- if (handlers == null)
+ if (handlers.size() == 0)
            return;
        
        for (int i = 0; i < responses.length; i++) { // go thru
responses
@@ -198,17 +200,15 @@
            if (r == null)
                continue;
 
- int size = handlers.size();
- if (size == 0)
- return;
            // Need to copy handlers list because handlers can be
removed
            // when handling a response.
- Object[] h = new Object[size];
- handlers.copyInto(h);
+ Object[] h = handlers.toArray();
 
            // dispatch 'em
- for (int j = 0; j < size; j++)
- ((ResponseHandler)h[j]).handleResponse(r);
+ for (int j = 0; j < h.length; j++) {
+ if (h[j] != null)
+ ((ResponseHandler)h[j]).handleResponse(r);
+ }
        }
     }