You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by fe...@apache.org on 2011/10/01 08:32:48 UTC

svn commit: r1177931 - /james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/AbstractDelegatingMailboxListener.java

Author: felixk
Date: Sat Oct  1 06:32:48 2011
New Revision: 1177931

URL: http://svn.apache.org/viewvc?rev=1177931&view=rev
Log:
Fix possible NPE in some cases.

Modified:
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/AbstractDelegatingMailboxListener.java

Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/AbstractDelegatingMailboxListener.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/AbstractDelegatingMailboxListener.java?rev=1177931&r1=1177930&r2=1177931&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/AbstractDelegatingMailboxListener.java (original)
+++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/AbstractDelegatingMailboxListener.java Sat Oct  1 06:32:48 2011
@@ -113,15 +113,20 @@ public abstract class AbstractDelegating
      */
     public void addListener(MailboxPath path, MailboxListener listener, MailboxSession session) throws MailboxException {
         Map<MailboxPath, List<MailboxListener>> listeners = getListeners();
-        synchronized (listeners) {
-            List<MailboxListener> mListeners = listeners.get(path);
-            if (mListeners == null) {
-                mListeners = new ArrayList<MailboxListener>();
-                listeners.put(path, mListeners);
+        
+        if (listeners != null) {
+            synchronized (listeners) {
+                List<MailboxListener> mListeners = listeners.get(path);
+                if (mListeners == null) {
+                    mListeners = new ArrayList<MailboxListener>();
+                    listeners.put(path, mListeners);
+                }
+                if (mListeners.contains(listener) == false) {
+                    mListeners.add(listener);
+                }        
             }
-            if (mListeners.contains(listener) == false) {
-                mListeners.add(listener);
-            }        
+        } else {
+            throw new MailboxException("Cannot add MailboxListener to null list");
         }
     }
 
@@ -132,8 +137,13 @@ public abstract class AbstractDelegating
      */
     public void addGlobalListener(MailboxListener listener, MailboxSession session) throws MailboxException {
         List<MailboxListener> gListeners = getGlobalListeners();
-        synchronized (gListeners) {
-            gListeners.add(listener);
+        
+        if (gListeners != null) {
+            synchronized (gListeners) {
+                gListeners.add(listener);
+            }
+        } else {
+            throw new MailboxException("Cannot add MailboxListener to null list");
         }
     }
 
@@ -145,15 +155,20 @@ public abstract class AbstractDelegating
      */
     public void removeListener(MailboxPath mailboxPath, MailboxListener listener, MailboxSession session) throws MailboxException {
         Map<MailboxPath, List<MailboxListener>> listeners = getListeners();
-        synchronized (listeners) {
-            List<MailboxListener> mListeners = listeners.get(mailboxPath);
-            if (mListeners != null) {
-                mListeners.remove(listener);
-                if (mListeners.isEmpty()) {
-                    listeners.remove(mailboxPath);
+        
+        if (listeners != null) {
+            synchronized (listeners) {
+                List<MailboxListener> mListeners = listeners.get(mailboxPath);
+                if (mListeners != null) {
+                    mListeners.remove(listener);
+                    if (mListeners.isEmpty()) {
+                        listeners.remove(mailboxPath);
+                    }
                 }
-            }        
-        }        
+            }
+        } else {
+            throw new MailboxException("Cannot remove MailboxListener from null list");
+        }
     }
 
     /*
@@ -167,6 +182,8 @@ public abstract class AbstractDelegating
             synchronized (gListeners) {
                 gListeners.remove(listener);
             }
+        } else {
+            throw new MailboxException("Cannot remove MailboxListener from null list");
         }
     }
 



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