commits@javamail.java.net

[mercurial:109] Add missing synchronization, found by FindBugs.

From: <shannon_at_kenai.com>
Date: Mon, 9 Feb 2009 19:41:02 +0000 (GMT)

Repository: mercurial
Revision: 109
Author: Bill Shannon <bill.shannon_at_sun.com>
Date: 2009-02-05 01:54:14 UTC

Log Message:
-----------
Add missing synchronization, found by FindBugs.

Modified Paths:
--------------
    mail/src/main/java/com/sun/mail/imap/DefaultFolder.java
    mail/src/main/java/com/sun/mail/imap/IMAPFolder.java
    mail/src/main/java/com/sun/mail/imap/protocol/SearchSequence.java

Diffs:
-----
diff -r 34245dfd41fa -r ec72506b3f2f
mail/src/main/java/com/sun/mail/imap/DefaultFolder.java
--- a/mail/src/main/java/com/sun/mail/imap/DefaultFolder.java Wed Feb
04 17:42:54 2009 -0800
+++ b/mail/src/main/java/com/sun/mail/imap/DefaultFolder.java Wed Feb
04 17:54:14 2009 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the
GNU
  * General Public License Version 2 only ("GPL") or the Common
Development
@@ -43,7 +43,7 @@
 import com.sun.mail.imap.protocol.*;
 
 /**
- * This class
+ * The default IMAP folder (root of the naming hierarchy).
  *
  * @author John Mani
  */
@@ -56,7 +56,7 @@
        type = HOLDS_FOLDERS; // obviously
     }
 
- public String getName() {
+ public synchronized String getName() {
        return fullName;
     }
 
@@ -64,7 +64,8 @@
        return null;
     }
 
- public Folder[] list(final String pattern) throws
MessagingException {
+ public synchronized Folder[] list(final String pattern)
+ throws MessagingException {
        ListInfo[] li = null;
 
        li = (ListInfo[])doCommand(new ProtocolCommand() {
@@ -82,7 +83,7 @@
        return folders;
     }
 
- public Folder[] listSubscribed(final String pattern)
+ public synchronized Folder[] listSubscribed(final String pattern)
                                throws MessagingException {
        ListInfo[] li = null;
 
diff -r 34245dfd41fa -r ec72506b3f2f
mail/src/main/java/com/sun/mail/imap/IMAPFolder.java
--- a/mail/src/main/java/com/sun/mail/imap/IMAPFolder.java Wed Feb
04 17:42:54 2009 -0800
+++ b/mail/src/main/java/com/sun/mail/imap/IMAPFolder.java Wed Feb
04 17:54:14 2009 -0800
@@ -377,6 +377,7 @@
      * Ensure that this folder exists. If 'exists' has been set to
true,
      * we don't attempt to validate it with the server again. Note
that
      * this can result in a possible loss of sync with the server.
+ * ASSERT: Must be called with this folder's synchronization lock
held.
      */
     private void checkExists() throws MessagingException {
        // If the boolean field 'exists' is false, check with the
@@ -824,7 +825,8 @@
     /**
      * Get the named subfolder. <p>
      */
- public Folder getFolder(String name) throws MessagingException {
+ public synchronized Folder getFolder(String name)
+ throws MessagingException {
        // If we know that this folder is *not* a directory, don't
        // send the request to the server at all ...
        if (attributes != null && !isDirectory())
@@ -2157,7 +2159,7 @@
      *
      * @since JavaMail 1.3.3
      */
- public String[] getAttributes() throws MessagingException {
+ public synchronized String[] getAttributes() throws
MessagingException {
        checkExists();
        if (attributes == null)
            exists(); // do a LIST to set the attributes
diff -r 34245dfd41fa -r ec72506b3f2f
mail/src/main/java/com/sun/mail/imap/protocol/SearchSequence.java
--- a/mail/src/main/java/com/sun/mail/imap/protocol/SearchSequence.java
Wed Feb 04 17:42:54 2009 -0800
+++ b/mail/src/main/java/com/sun/mail/imap/protocol/SearchSequence.java
Wed Feb 04 17:54:14 2009 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the
GNU
  * General Public License Version 2 only ("GPL") or the Common
Development
@@ -358,7 +358,10 @@
     // A GregorianCalendar object in the current timezone
     private static Calendar cal = new GregorianCalendar();
 
- private static String toIMAPDate(Date date) {
+ /*
+ * Synchronized to coordinate access to shared Calendar object.
+ */
+ private static synchronized String toIMAPDate(Date date) {
        StringBuffer s = new StringBuffer();
        cal.setTime(date);