commits@javamail.java.net

[javamail~mercurial:367] Move FindBugs configuration to top level pom so it can be used in other m

From: <shannon_at_kenai.com>
Date: Wed, 9 Mar 2011 19:15:59 +0000

Project: javamail
Repository: mercurial
Revision: 367
Author: shannon
Date: 2011-03-09 19:10:06 UTC
Link:

Log Message:
------------
Version is now 1.4.5-SNAPSHOT.
Fix MultipartReport.setReport and setDeliveryStatus - Kenai bug 4002
Clone DataFlavors array before returning.
Add missing synchronization.
Change code to avoid FindBugs complaint about ignoring exception on close().
Remove dead store to local variable.
Make transportListeners volatile (like storeListeners) to solve FindBugs
detected synchronization error.
Make msgnum volatile since it's not consistently synchronized.
Fix synchronization of trustAllHosts and trustedHosts.
Make protocolConnect synchronized. FindBugs can't seem to figure out that
the protocolConnect method is only ever called from the synchronized connect
method.
Make updateHeaders method synchronized to protect dh field.
Make flags field volatile, it's touched in just too many places to
properly synchronize.
Choose proper encoding for unusual charsets such as utf-16.
Any charset that isn't compatible with ASCII should be encoded
with base64 if the text has any non-ASCII characters.
Exclude some FindBugs errors.
Run FindBugs on dsn module.
Make FindBugs threshold a property so it can be overridden on the command
line, e.g., "mvn -Dfindbugs.threshold=Default".
getContentType needs to be synchronized to protect access to the type field.
idleTag needs to be volatile because it's accessed in processIdleResponse
without the protocol object being locked.
FindBugs says the port field is not consistently synchronized.
It might be right but I can't figure out why it's not also complaining
about the host and user fields. Make the port field volatile for now.
Make a bunch of fields volatile to address inconsistent synchronization issues.
Keep FindBugs happy, catch more specific exceptions.
Exclude some errors that I believe are not really errors.
Consistently synchronize access to capabilities field.
Consistently synchronize access to contentType field.
Consistently synchronize access to mode field.
Fix potential deadlock due to lock order violation.
Make sure the POP3Message object lock isn't held when calling
folder.close() due to a protocol failure.
Non-ASCII charset test was entirely backwards, and there was no test case
to find the problem. Sigh.
Add bug ID for charset encoding bug.
Fix impossible cast.
Fix FindBugs errors in mbox provider.
Fix FindBugs errors in demos.
setRecipients with a null String address should remove the header - bug 7021190
Fix another off-by-one bug in the code that figures out when to insert CRLF.
Add a test.
Move FindBugs configuration to top level pom so it can be used in other modules.


Revisions:
----------
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367


Modified Paths:
---------------
client/pom.xml
demo/pom.xml
dsn/pom.xml
imap/pom.xml
javadoc/pom.xml
logging/pom.xml
mail/pom.xml
mailapi/pom.xml
mailapijar/pom.xml
mbox/dist/pom.xml
mbox/native/pom.xml
mbox/pom.xml
oldmail/pom.xml
outlook/pom.xml
parent-distrib/pom.xml
pom.xml
pop3/pom.xml
servlet/pom.xml
smtp/pom.xml
taglib/pom.xml
webapp/pom.xml
doc/release/CHANGES.txt
dsn/src/main/java/com/sun/mail/dsn/MultipartReport.java
mail/src/main/java/com/sun/mail/handlers/text_xml.java
mail/src/main/java/javax/mail/util/SharedFileInputStream.java
mail/src/main/java/com/sun/mail/pop3/TempFile.java
mail/src/main/java/javax/mail/Transport.java
mail/src/main/java/javax/mail/Message.java
mail/src/main/java/com/sun/mail/util/MailSSLSocketFactory.java
mail/src/main/java/com/sun/mail/smtp/SMTPTransport.java
mail/src/main/java/com/sun/mail/pop3/POP3Message.java
mail/src/main/java/javax/mail/internet/MimeMessage.java
mail/src/main/java/javax/mail/internet/MimeUtility.java
mail/exclude.xml
mail/src/main/java/com/sun/mail/imap/IMAPMessage.java
mail/src/main/java/com/sun/mail/imap/protocol/IMAPProtocol.java
mail/src/main/java/com/sun/mail/imap/IMAPStore.java
mail/src/main/java/com/sun/mail/imap/IMAPFolder.java
mail/src/main/java/com/sun/mail/util/MimeUtil.java
mail/src/main/java/com/sun/mail/pop3/POP3Store.java
mail/src/main/java/javax/mail/Multipart.java
mail/src/main/java/javax/mail/Folder.java
outlook/src/main/java/MSMessage.java
mbox/src/main/java/com/sun/mail/mbox/ContentLengthCounter.java
mbox/src/main/java/com/sun/mail/mbox/DefaultMailbox.java
mbox/src/main/java/com/sun/mail/mbox/MboxFolder.java
mbox/src/main/java/com/sun/mail/mbox/MessageLoader.java
mbox/src/main/java/com/sun/mail/mbox/TempFile.java
mbox/src/main/java/com/sun/mail/mbox/UNIXFolder.java
mbox/src/main/java/com/sun/mail/mbox/UNIXInbox.java
demo/src/main/java/msgsendsample.java
demo/src/main/java/transport.java
outlook/src/main/java/MSBodyPart.java
servlet/src/main/java/JavaMailServlet.java
mail/src/main/java/com/sun/mail/util/BASE64EncoderStream.java
mail/src/test/java/com/sun/mail/util/BASE64Test.java


Added Paths:
------------
dsn/src/test/java/com/sun/mail/dsn/MultipartReportTest.java
dsn/src/test/java/com/sun/mail/dsn/NullOutputStream.java
mail/src/test/java/javax/mail/internet/MimeUtilityTest.java
mbox/exclude.xml
mail/src/test/java/javax/mail/internet/MimeMessageTest.java


Diffs:
------
diff -r c3debabaa778 -r 1e32fa90f44b client/pom.xml
--- a/client/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/client/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r c3debabaa778 -r 1e32fa90f44b demo/pom.xml
--- a/demo/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/demo/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r c3debabaa778 -r 1e32fa90f44b dsn/pom.xml
--- a/dsn/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/dsn/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r c3debabaa778 -r 1e32fa90f44b imap/pom.xml
--- a/imap/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/imap/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>parent-distrib</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
         <relativePath>../parent-distrib/pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>

diff -r c3debabaa778 -r 1e32fa90f44b javadoc/pom.xml
--- a/javadoc/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/javadoc/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -48,13 +48,13 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>
     <artifactId>javadoc</artifactId>
     <packaging>pom</packaging>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
     <name>JavaMail API javadocs</name>
     <description>${project.name}</description>
 

diff -r c3debabaa778 -r 1e32fa90f44b logging/pom.xml
--- a/logging/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/logging/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r c3debabaa778 -r 1e32fa90f44b mail/pom.xml
--- a/mail/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/mail/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r c3debabaa778 -r 1e32fa90f44b mailapi/pom.xml
--- a/mailapi/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/mailapi/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -56,7 +56,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r c3debabaa778 -r 1e32fa90f44b mailapijar/pom.xml
--- a/mailapijar/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/mailapijar/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -55,7 +55,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>javax.mail</groupId>

diff -r c3debabaa778 -r 1e32fa90f44b mbox/dist/pom.xml
--- a/mbox/dist/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/mbox/dist/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
         <relativePath>../../pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>

diff -r c3debabaa778 -r 1e32fa90f44b mbox/native/pom.xml
--- a/mbox/native/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/mbox/native/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
         <relativePath>../../pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>

diff -r c3debabaa778 -r 1e32fa90f44b mbox/pom.xml
--- a/mbox/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/mbox/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r c3debabaa778 -r 1e32fa90f44b oldmail/pom.xml
--- a/oldmail/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/oldmail/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -53,7 +53,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>javax.mail</groupId>

diff -r c3debabaa778 -r 1e32fa90f44b outlook/pom.xml
--- a/outlook/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/outlook/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r c3debabaa778 -r 1e32fa90f44b parent-distrib/pom.xml
--- a/parent-distrib/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/parent-distrib/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r c3debabaa778 -r 1e32fa90f44b pom.xml
--- a/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -49,7 +49,7 @@
     <groupId>com.sun.mail</groupId>
     <artifactId>all</artifactId>
     <packaging>pom</packaging>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
     <name>JavaMail API distribution</name>
     <description>${project.name}</description>
     <url>http://kenai.com/projects/javamail</url>
@@ -75,9 +75,9 @@
     </organization>
 
     <properties>
- <mail.version>1.4.4</mail.version>
+ <mail.version>1.4.5-SNAPSHOT</mail.version>
         <!-- like mail.version, but with underscores instead of dots -->
- <mail.zipversion>1_4_4</mail.zipversion>
+ <mail.zipversion>1_4_5-SNAPSHOT</mail.zipversion>
         <mail.spec.version>1.4</mail.spec.version>
         <activation-api.version>1.1</activation-api.version>
         <!-- defaults that are overridden in mail module -->

diff -r c3debabaa778 -r 1e32fa90f44b pop3/pom.xml
--- a/pop3/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/pop3/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>parent-distrib</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
         <relativePath>../parent-distrib/pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>

diff -r c3debabaa778 -r 1e32fa90f44b servlet/pom.xml
--- a/servlet/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/servlet/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r c3debabaa778 -r 1e32fa90f44b smtp/pom.xml
--- a/smtp/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/smtp/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>parent-distrib</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
         <relativePath>../parent-distrib/pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>

diff -r c3debabaa778 -r 1e32fa90f44b taglib/pom.xml
--- a/taglib/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/taglib/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r c3debabaa778 -r 1e32fa90f44b webapp/pom.xml
--- a/webapp/pom.xml Fri Jan 14 15:16:33 2011 -0800
+++ b/webapp/pom.xml Mon Jan 24 16:28:06 2011 -0800
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>


diff -r 1e32fa90f44b -r 45a2301c4acf doc/release/CHANGES.txt
--- a/doc/release/CHANGES.txt Mon Jan 24 16:28:06 2011 -0800
+++ b/doc/release/CHANGES.txt Tue Feb 01 14:03:55 2011 -0800
@@ -14,6 +14,13 @@
         https://kenai.com/bugzilla/
 
 
+ CHANGES IN THE 1.4.5 RELEASE
+ ----------------------------
+The following bugs have been fixed in the 1.4.5 release.
+
+K 4002 MultipartReport.setReport and setDeliveryStatus are broken
+
+
                   CHANGES IN THE 1.4.4 RELEASE
                   ----------------------------
 The following bugs have been fixed in the 1.4.4 release.

diff -r 1e32fa90f44b -r 45a2301c4acf dsn/pom.xml
--- a/dsn/pom.xml Mon Jan 24 16:28:06 2011 -0800
+++ b/dsn/pom.xml Tue Feb 01 14:03:55 2011 -0800
@@ -67,5 +67,12 @@
             <groupId>com.sun.mail</groupId>
             <artifactId>javax.mail</artifactId>
         </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.7</version>
+ <scope>test</scope>
+ <optional>true</optional>
+ </dependency>
     </dependencies>
 </project>

diff -r 1e32fa90f44b -r 45a2301c4acf dsn/src/main/java/com/sun/mail/dsn/MultipartReport.java
--- a/dsn/src/main/java/com/sun/mail/dsn/MultipartReport.java Mon Jan 24 16:28:06 2011 -0800
+++ b/dsn/src/main/java/com/sun/mail/dsn/MultipartReport.java Tue Feb 01 14:03:55 2011 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
@@ -250,7 +250,7 @@
         contentType = ct.toString();
         ct = new ContentType("message", reportType, null);
         mbp.setContent(report, ct.toString());
- setBodyPart(mbp, 2);
+ setBodyPart(mbp, 1);
     }
 
     /**
@@ -282,7 +282,7 @@
                                 throws MessagingException {
         MimeBodyPart mbp = new MimeBodyPart();
         mbp.setContent(status, "message/delivery-status");
- setBodyPart(mbp, 2);
+ setBodyPart(mbp, 1);
         ContentType ct = new ContentType(contentType);
         ct.setParameter("report-type", "delivery-status");
         contentType = ct.toString();

diff -r 1e32fa90f44b -r 45a2301c4acf dsn/src/test/java/com/sun/mail/dsn/MultipartReportTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dsn/src/test/java/com/sun/mail/dsn/MultipartReportTest.java Tue Feb 01 14:03:55 2011 -0800
@@ -0,0 +1,82 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright (c) 2010-2011 Oracle and/or its affiliates. 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
+ * and Distribution License("CDDL") (collectively, the "License"). You
+ * may not use this file except in compliance with the License. You can
+ * obtain a copy of the License at
+ * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
+ * or packager/legal/LICENSE.txt. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at packager/legal/LICENSE.txt.
+ *
+ * GPL Classpath Exception:
+ * Oracle designates this particular file as subject to the "Classpath"
+ * exception as provided by Oracle in the GPL Version 2 section of the License
+ * file that accompanied this code.
+ *
+ * Modifications:
+ * If applicable, add the following below the License Header, with the fields
+ * enclosed by brackets [] replaced by your own identifying information:
+ * "Portions Copyright [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or GPL
+ * Version 2] license." If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above. However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+
+package com.sun.mail.dsn;
+
+import java.util.Properties;
+
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.InternetHeaders;
+
+import org.junit.*;
+import static org.junit.Assert.assertTrue;
+
+/**
+ */
+public class MultipartReportTest {
+
+ private static Session session = Session.getInstance(new Properties());
+
+ @Test
+ public void testWrongIndexBug() throws Exception {
+ MimeMessage msg = new MimeMessage(session);
+
+ // create the Multipart and its parts to it
+ MultipartReport mp = new MultipartReport();
+ mp.setText("test Multipart Report\n");
+
+ DeliveryStatus ds = new DeliveryStatus();
+ InternetHeaders mdsn = new InternetHeaders();
+ mdsn.setHeader("Reporting-MTA", "test");
+ ds.setMessageDSN(mdsn);
+ InternetHeaders rdsn = new InternetHeaders();
+ rdsn.setHeader("Final-Recipient", "joe");
+ rdsn.setHeader("Action", "none");
+ rdsn.setHeader("Status", "none");
+ ds.addRecipientDSN(rdsn);
+ mp.setReport(ds);
+ msg.setContent(mp);
+ msg.saveChanges();
+ msg.writeTo(new NullOutputStream());
+ // anything other than an exception is success
+ assertTrue("MultipartReport constructed", true);
+ }
+}

diff -r 1e32fa90f44b -r 45a2301c4acf dsn/src/test/java/com/sun/mail/dsn/NullOutputStream.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dsn/src/test/java/com/sun/mail/dsn/NullOutputStream.java Tue Feb 01 14:03:55 2011 -0800
@@ -0,0 +1,58 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright (c) 2009-2011 Oracle and/or its affiliates. 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
+ * and Distribution License("CDDL") (collectively, the "License"). You
+ * may not use this file except in compliance with the License. You can
+ * obtain a copy of the License at
+ * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
+ * or packager/legal/LICENSE.txt. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at packager/legal/LICENSE.txt.
+ *
+ * GPL Classpath Exception:
+ * Oracle designates this particular file as subject to the "Classpath"
+ * exception as provided by Oracle in the GPL Version 2 section of the License
+ * file that accompanied this code.
+ *
+ * Modifications:
+ * If applicable, add the following below the License Header, with the fields
+ * enclosed by brackets [] replaced by your own identifying information:
+ * "Portions Copyright [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or GPL
+ * Version 2] license." If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above. However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+
+package com.sun.mail.dsn;
+
+import java.io.*;
+
+/**
+ * An OutputStream that throws away all data written to it.
+ */
+public class NullOutputStream extends OutputStream {
+
+ public void write(int b) throws IOException {
+ }
+
+ public void write(byte[] b) throws IOException {
+ }
+
+ public void write(byte[] b, int off, int len) throws IOException {
+ }
+}


diff -r 45a2301c4acf -r d05b530a1f11 mail/src/main/java/com/sun/mail/handlers/text_xml.java
--- a/mail/src/main/java/com/sun/mail/handlers/text_xml.java Tue Feb 01 14:03:55 2011 -0800
+++ b/mail/src/main/java/com/sun/mail/handlers/text_xml.java Tue Feb 01 14:36:31 2011 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
@@ -81,7 +81,7 @@
      * @return the DataFlavors
      */
     public DataFlavor[] getTransferDataFlavors() { // throws Exception;
- return flavors;
+ return (DataFlavor[])flavors.clone();
     }
 
     /**


diff -r d05b530a1f11 -r bd018fab11a4 mail/src/main/java/javax/mail/util/SharedFileInputStream.java
--- a/mail/src/main/java/javax/mail/util/SharedFileInputStream.java Tue Feb 01 14:36:31 2011 -0800
+++ b/mail/src/main/java/javax/mail/util/SharedFileInputStream.java Tue Feb 01 15:24:42 2011 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
@@ -120,7 +120,7 @@
             this.in = new RandomAccessFile(file, "r");
         }
 
- public RandomAccessFile open() {
+ public synchronized RandomAccessFile open() {
             cnt++;
             return in;
         }
@@ -502,7 +502,7 @@
      * @param end the ending position + 1
      * @return the new stream
      */
- public InputStream newStream(long start, long end) {
+ public synchronized InputStream newStream(long start, long end) {
         if (in == null)
             throw new RuntimeException("Stream closed");
         if (start < 0)


diff -r bd018fab11a4 -r cfe1274bab70 mail/src/main/java/com/sun/mail/pop3/TempFile.java
--- a/mail/src/main/java/com/sun/mail/pop3/TempFile.java Tue Feb 01 15:24:42 2011 -0800
+++ b/mail/src/main/java/com/sun/mail/pop3/TempFile.java Tue Feb 01 15:25:37 2011 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010-2011 Oracle and/or its affiliates. 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
@@ -80,7 +80,9 @@
     public void close() {
         try {
             sf.close();
- } catch (IOException ex) { } // ignore it
+ } catch (IOException ex) {
+ // ignore it
+ }
         file.delete();
     }
 


diff -r cfe1274bab70 -r c9e282d1a7d7 dsn/src/main/java/com/sun/mail/dsn/MultipartReport.java
--- a/dsn/src/main/java/com/sun/mail/dsn/MultipartReport.java Tue Feb 01 15:25:37 2011 -0800
+++ b/dsn/src/main/java/com/sun/mail/dsn/MultipartReport.java Tue Feb 01 15:44:25 2011 -0800
@@ -318,7 +318,6 @@
     public synchronized void setReturnedMessage(MimeMessage msg)
                                 throws MessagingException {
         if (msg == null) {
- BodyPart part = (BodyPart)parts.elementAt(2);
             super.removeBodyPart(2);
             return;
         }


diff -r c9e282d1a7d7 -r eaf6e832b5b7 mail/src/main/java/javax/mail/Transport.java
--- a/mail/src/main/java/javax/mail/Transport.java Tue Feb 01 15:44:25 2011 -0800
+++ b/mail/src/main/java/javax/mail/Transport.java Thu Feb 03 14:54:35 2011 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
@@ -306,7 +306,7 @@
                                 throws MessagingException;
 
     // Vector of Transport listeners
- private Vector transportListeners = null;
+ private volatile Vector transportListeners = null;
 
     /**
      * Add a listener for Transport events. <p>


diff -r eaf6e832b5b7 -r e1e5ac736c4a mail/src/main/java/javax/mail/Message.java
--- a/mail/src/main/java/javax/mail/Message.java Thu Feb 03 14:54:35 2011 -0800
+++ b/mail/src/main/java/javax/mail/Message.java Thu Feb 03 14:58:05 2011 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
@@ -86,7 +86,7 @@
      * The number of this message within its folder, or zero if
      * the message was not retrieved from a folder.
      */
- protected int msgnum = 0;
+ protected volatile int msgnum = 0;
 
     /**
      * True if this message has been expunged.


diff -r e1e5ac736c4a -r 55ccfca1a013 mail/src/main/java/com/sun/mail/util/MailSSLSocketFactory.java
--- a/mail/src/main/java/com/sun/mail/util/MailSSLSocketFactory.java Thu Feb 03 14:58:05 2011 -0800
+++ b/mail/src/main/java/com/sun/mail/util/MailSSLSocketFactory.java Thu Feb 03 15:05:31 2011 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
@@ -340,7 +340,7 @@
          */
         public void checkClientTrusted(X509Certificate[] certs, String authType)
                                         throws CertificateException {
- if (!(trustAllHosts || trustedHosts != null))
+ if (!(isTrustAllHosts() || getTrustedHosts() != null))
                 adapteeTrustManager.checkClientTrusted(certs, authType);
         }
 
@@ -351,7 +351,7 @@
         public void checkServerTrusted(X509Certificate[] certs, String authType)
                                         throws CertificateException {
 
- if (!(trustAllHosts || trustedHosts != null))
+ if (!(isTrustAllHosts() || getTrustedHosts() != null))
                 adapteeTrustManager.checkServerTrusted(certs, authType);
         }
 


diff -r 55ccfca1a013 -r 7af6bc2d8007 mail/src/main/java/com/sun/mail/smtp/SMTPTransport.java
--- a/mail/src/main/java/com/sun/mail/smtp/SMTPTransport.java Thu Feb 03 15:05:31 2011 -0800
+++ b/mail/src/main/java/com/sun/mail/smtp/SMTPTransport.java Thu Feb 03 15:38:50 2011 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
@@ -590,8 +590,8 @@
      * @return true if connection successful, false if authentication failed
      * @exception MessagingException for non-authentication failures
      */
- protected boolean protocolConnect(String host, int port, String user,
- String passwd) throws MessagingException {
+ protected synchronized boolean protocolConnect(String host, int port,
+ String user, String passwd) throws MessagingException {
         // setting mail.smtp.ehlo to false disables attempts to use EHLO
         boolean useEhlo = PropUtil.getBooleanSessionProperty(session,
                                         "mail." + name + ".ehlo", true);


diff -r 7af6bc2d8007 -r dd81b269a795 mail/src/main/java/com/sun/mail/pop3/POP3Message.java
--- a/mail/src/main/java/com/sun/mail/pop3/POP3Message.java Thu Feb 03 15:38:50 2011 -0800
+++ b/mail/src/main/java/com/sun/mail/pop3/POP3Message.java Thu Feb 03 16:03:11 2011 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
@@ -84,7 +84,7 @@
      * @param newFlags the flags to be set
      * @param set the value to be set
      */
- public void setFlags(Flags newFlags, boolean set)
+ public synchronized void setFlags(Flags newFlags, boolean set)
                                 throws MessagingException {
         Flags oldFlags = (Flags)flags.clone();
         super.setFlags(newFlags, set);

diff -r 7af6bc2d8007 -r dd81b269a795 mail/src/main/java/javax/mail/internet/MimeMessage.java
--- a/mail/src/main/java/javax/mail/internet/MimeMessage.java Thu Feb 03 15:38:50 2011 -0800
+++ b/mail/src/main/java/javax/mail/internet/MimeMessage.java Thu Feb 03 16:03:11 2011 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
@@ -132,7 +132,7 @@
     /**
      * The Flags for this message.
      */
- protected Flags flags;
+ protected volatile Flags flags;
 
     /**
      * A flag indicating whether the message has been modified.
@@ -2093,7 +2093,7 @@
      * <code>Content-Transfer-Encoding</code> header (if needed
      * and not already set), the <code>MIME-Version</code> header
      * and the <code>Message-ID</code> header. Also, if the content
- * of this message is a <code>MimeMultipart</code>, it's
+ * of this message is a <code>MimeMultipart</code>, its
      * <code>updateHeaders</code> method is called.
      *
      * @exception IllegalWriteException if the underlying
@@ -2102,7 +2102,7 @@
      * obtained from a READ_ONLY folder.
      * @exception MessagingException
      */
- protected void updateHeaders() throws MessagingException {
+ protected synchronized void updateHeaders() throws MessagingException {
         MimeBodyPart.updateHeaders(this);
         setHeader("MIME-Version", "1.0");
         updateMessageID();


diff -r dd81b269a795 -r 5de494c91227 mail/src/main/java/javax/mail/internet/MimeUtility.java
--- a/mail/src/main/java/javax/mail/internet/MimeUtility.java Thu Feb 03 16:03:11 2011 -0800
+++ b/mail/src/main/java/javax/mail/internet/MimeUtility.java Thu Feb 03 16:08:13 2011 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
@@ -145,6 +145,10 @@
 
     public static final int ALL = -1;
 
+ // cached map of whether a charset is compatible with ASCII
+ // Map<String,Boolean>
+ private static final Map nonAsciiCharsetMap = new HashMap();
+
     private static final boolean decodeStrict =
         PropUtil.getBooleanSystemProperty("mail.mime.decodetext.strict", true);
     private static final boolean encodeEolStrict =
@@ -195,31 +199,70 @@
         try {
             cType = new ContentType(ds.getContentType());
             is = ds.getInputStream();
+
+ boolean isText = cType.match("text/*");
+ // if not text, stop processing when we see non-ASCII
+ int i = checkAscii(is, ALL, !isText);
+ switch (i) {
+ case ALL_ASCII:
+ encoding = "7bit"; // all ASCII
+ break;
+ case MOSTLY_ASCII:
+ if (isText && nonAsciiCharset(cType))
+ encoding = "base64"; // charset isn't compatible with ASCII
+ else
+ encoding = "quoted-printable"; // mostly ASCII
+ break;
+ default:
+ encoding = "base64"; // mostly binary
+ break;
+ }
+
         } catch (Exception ex) {
             return "base64"; // what else ?!
+ } finally {
+ // Close the input stream
+ try {
+ is.close();
+ } catch (IOException ioex) { }
         }
 
- boolean isText = cType.match("text/*");
- // if not text, stop processing when we see non-ASCII
- int i = checkAscii(is, ALL, !isText);
- switch (i) {
- case ALL_ASCII:
- encoding = "7bit"; // all ascii
- break;
- case MOSTLY_ASCII:
- encoding = "quoted-printable"; // mostly ascii
- break;
- default:
- encoding = "base64"; // mostly binary
- break;
+ return encoding;
+ }
+
+ /**
+ * Determine whether the charset in the Content-Type is compatible
+ * with ASCII or not. A charset is compatible with ASCII if the
+ * encoded byte stream representing the Unicode string "\r\n" is
+ * the ASCII characters CR and LF. For example, the utf-16be
+ * charset is not compatible with ASCII.
+ *
+ * For performance, we keep a static map that caches the results.
+ */
+ private static boolean nonAsciiCharset(ContentType ct) {
+ String charset = ct.getParameter("charset");
+ if (charset == null)
+ return false;
+ charset = charset.toLowerCase(Locale.ENGLISH);
+ Boolean bool;
+ synchronized (nonAsciiCharsetMap) {
+ bool = (Boolean)nonAsciiCharsetMap.get(charset);
         }
-
- // Close the input stream
- try {
- is.close();
- } catch (IOException ioex) { }
-
- return encoding;
+ if (bool == null) {
+ try {
+ byte[] b = "\r\n".getBytes(charset);
+ bool = Boolean.valueOf(
+ b != null && b.length == 2 && b[0] == 015 && b[1] == 012);
+ } catch (UnsupportedEncodingException uex) {
+ bool = Boolean.FALSE; // a guess
+ } catch (RuntimeException ex) {
+ bool = Boolean.TRUE; // one of the weird ones?
+ }
+ synchronized (nonAsciiCharsetMap) {
+ nonAsciiCharsetMap.put(charset, bool);
+ }
+ }
+ return bool.booleanValue();
     }
 
     /**


diff -r 5de494c91227 -r 14ea58df930a mail/exclude.xml
--- a/mail/exclude.xml Thu Feb 03 16:08:13 2011 -0800
+++ b/mail/exclude.xml Thu Feb 03 16:09:47 2011 -0800
@@ -3,7 +3,7 @@
 
     DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
- Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2010-2011 Oracle and/or its affiliates. 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
@@ -307,4 +307,37 @@
         </Or>
         <Bug pattern="OS_OPEN_STREAM"/>
     </Match>
+
+ <!--
+ When deleting the temp file fails, there's really nothing to be done.
+ -->
+ <Match>
+ <Class name="com.sun.mail.pop3.TempFile"/>
+ <Method name="close"/>
+ <Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE"/>
+ </Match>
+
+ <!--
+ In IMAPFolder.close, I believe the protocol field can be set to null
+ as a result of a protocol error that invokes a callback that calls
+ cleanup, thus I don't believe these null checks are redundant.
+ -->
+ <Match>
+ <Class name="com.sun.mail.imap.IMAPFolder"/>
+ <Method name="close"/>
+ <Bug pattern="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"/>
+ </Match>
+
+ <!--
+ Can't fix these errors in toString until JavaMail 1.5 because
+ it's part of the spec. Sigh.
+ -->
+ <Match>
+ <Or>
+ <Class name="javax.mail.internet.ContentDisposition"/>
+ <Class name="javax.mail.internet.ContentType"/>
+ </Or>
+ <Method name="toString"/>
+ <Bug pattern="NP_TOSTRING_COULD_RETURN_NULL"/>
+ </Match>
 </FindBugsFilter>


diff -r 14ea58df930a -r cbc10c57a470 dsn/pom.xml
--- a/dsn/pom.xml Thu Feb 03 16:09:47 2011 -0800
+++ b/dsn/pom.xml Thu Feb 03 16:11:13 2011 -0800
@@ -62,6 +62,29 @@
         </mail.packages.export>
     </properties>
 
+ <build>
+ <plugins>
+ <!--
+ Configure FindBugs to run with "mvn findbugs:findbugs"
+ and generate XML output that can be used by the Hudson
+ FindBugs plugin.
+ -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ <threshold>${findbugs.threshold}</threshold>
+ <!--
+ <excludeFilterFile>exclude.xml</excludeFilterFile>
+ -->
+ <findbugsXmlOutput>true</findbugsXmlOutput>
+ <findbugsXmlWithMessages>true</findbugsXmlWithMessages>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
     <dependencies>
         <dependency>
             <groupId>com.sun.mail</groupId>
@@ -75,4 +98,24 @@
             <optional>true</optional>
         </dependency>
     </dependencies>
+
+ <reporting>
+ <plugins>
+ <!--
+ Configure FindBugs to run with "mvn site" and
+ generate html output that can be viewed directly.
+ -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ <threshold>${findbugs.threshold}</threshold>
+ <!--
+ <excludeFilterFile>exclude.xml</excludeFilterFile>
+ -->
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
 </project>


diff -r cbc10c57a470 -r fdf8f314fd22 mail/pom.xml
--- a/mail/pom.xml Thu Feb 03 16:11:13 2011 -0800
+++ b/mail/pom.xml Thu Feb 03 16:12:20 2011 -0800
@@ -100,7 +100,7 @@
                 <artifactId>findbugs-maven-plugin</artifactId>
                 <configuration>
                     <skip>false</skip>
- <threshold>Normal</threshold>
+ <threshold>${findbugs.threshold}</threshold>
                     <excludeFilterFile>exclude.xml</excludeFilterFile>
                     <findbugsXmlOutput>true</findbugsXmlOutput>
                     <findbugsXmlWithMessages>true</findbugsXmlWithMessages>
@@ -144,7 +144,7 @@
                 <artifactId>findbugs-maven-plugin</artifactId>
                 <configuration>
                     <skip>false</skip>
- <threshold>Normal</threshold>
+ <threshold>${findbugs.threshold}</threshold>
                     <excludeFilterFile>exclude.xml</excludeFilterFile>
                 </configuration>
             </plugin>

diff -r cbc10c57a470 -r fdf8f314fd22 pom.xml
--- a/pom.xml Thu Feb 03 16:11:13 2011 -0800
+++ b/pom.xml Thu Feb 03 16:12:20 2011 -0800
@@ -110,6 +110,9 @@
         <hk2.plugin.version>0.4.11</hk2.plugin.version>
         <javac.path>/opt/jdk1.4/bin/javac</javac.path>
         <project.build.sourceEncoding>iso-8859-1</project.build.sourceEncoding>
+ <findbugs.threshold>
+ High
+ </findbugs.threshold>
     </properties>
 
     <developers>


diff -r fdf8f314fd22 -r d60df45045a9 mail/src/main/java/com/sun/mail/imap/IMAPMessage.java
--- a/mail/src/main/java/com/sun/mail/imap/IMAPMessage.java Thu Feb 03 16:12:20 2011 -0800
+++ b/mail/src/main/java/com/sun/mail/imap/IMAPMessage.java Fri Feb 04 17:50:05 2011 -0800
@@ -442,7 +442,7 @@
      * Generate this header from the BODYSTRUCTURE. Append parameters
      * as well.
      */
- public String getContentType() throws MessagingException {
+ public synchronized String getContentType() throws MessagingException {
         checkExpunged();
 
         // If we haven't cached the type yet ..


diff -r d60df45045a9 -r 9eb78fe93454 mail/src/main/java/com/sun/mail/imap/protocol/IMAPProtocol.java
--- a/mail/src/main/java/com/sun/mail/imap/protocol/IMAPProtocol.java Fri Feb 04 17:50:05 2011 -0800
+++ b/mail/src/main/java/com/sun/mail/imap/protocol/IMAPProtocol.java Fri Feb 04 17:53:15 2011 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
@@ -2205,7 +2205,7 @@
      * used in processIdleResponse() to determine if the response
      * is the matching end tag.
      */
- private String idleTag;
+ private volatile String idleTag;
 
     /**
      * IDLE Command. <p>


diff -r 9eb78fe93454 -r 2fabd164f651 mail/src/main/java/com/sun/mail/imap/IMAPStore.java
--- a/mail/src/main/java/com/sun/mail/imap/IMAPStore.java Fri Feb 04 17:53:15 2011 -0800
+++ b/mail/src/main/java/com/sun/mail/imap/IMAPStore.java Fri Feb 04 17:55:02 2011 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
@@ -170,7 +170,7 @@
 
     private final int minIdleTime; // minimum idle time
 
- private int port = -1; // port to use
+ private volatile int port = -1; // port to use
 
     // Auth info
     private String host;


diff -r 2fabd164f651 -r f3da7de7bf22 mail/src/main/java/com/sun/mail/imap/IMAPFolder.java
--- a/mail/src/main/java/com/sun/mail/imap/IMAPFolder.java Fri Feb 04 17:55:02 2011 -0800
+++ b/mail/src/main/java/com/sun/mail/imap/IMAPFolder.java Fri Feb 04 17:56:09 2011 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
@@ -162,11 +162,11 @@
     protected char separator; // separator
     protected Flags availableFlags; // available flags
     protected Flags permanentFlags; // permanent flags
- protected boolean exists = false; // whether this folder really exists ?
+ protected volatile boolean exists; // whether this folder really exists ?
     protected boolean isNamespace = false; // folder is a namespace name
- protected String[] attributes; // name attributes from LIST response
+ protected volatile String[] attributes;// name attributes from LIST response
 
- protected IMAPProtocol protocol; // this folder's own protocol object
+ protected volatile IMAPProtocol protocol; // this folder's protocol object
     protected MessageCache messageCache;// message cache
     // accessor lock for message cache
     protected final Object messageCacheLock = new Object();
@@ -181,7 +181,7 @@
      */
     static final protected char UNKNOWN_SEPARATOR = '\uffff';
 
- private boolean opened = false; // is this folder opened ?
+ private volatile boolean opened = false; // is this folder opened ?
 
     /* This field tracks the state of this folder. If the folder is closed
      * due to external causes (i.e, not thru the close() method), then
@@ -247,9 +247,9 @@
     private static final int ABORTING = 2; // IDLE command aborting
     private int idleState = RUNNING;
 
- private int total = -1; // total number of messages in the
+ private volatile int total = -1; // total number of messages in the
                                         // message cache
- private int recent = -1; // number of recent messages
+ private volatile int recent = -1; // number of recent messages
     private int realTotal = -1; // total number of messages on
                                             // the server
     private long uidvalidity = -1; // UIDValidity


diff -r f3da7de7bf22 -r d672baf56dc6 mail/src/main/java/com/sun/mail/util/MimeUtil.java
--- a/mail/src/main/java/com/sun/mail/util/MimeUtil.java Fri Feb 04 17:56:09 2011 -0800
+++ b/mail/src/main/java/com/sun/mail/util/MimeUtil.java Fri Feb 04 18:04:21 2011 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010-2011 Oracle and/or its affiliates. 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
@@ -72,7 +72,11 @@
                 meth = clsHandler.getMethod("cleanContentType",
                                 new Class[] { MimePart.class, String.class });
             }
- } catch (Exception ex) {
+ } catch (ClassNotFoundException ex) {
+ // ignore it
+ } catch (NoSuchMethodException ex) {
+ // ignore it
+ } catch (RuntimeException ex) {
             // ignore it
         } finally {
             cleanContentType = meth;


diff -r d672baf56dc6 -r ce5c9e0d6532 mail/exclude.xml
--- a/mail/exclude.xml Fri Feb 04 18:04:21 2011 -0800
+++ b/mail/exclude.xml Fri Feb 04 18:05:11 2011 -0800
@@ -340,4 +340,24 @@
         <Method name="toString"/>
         <Bug pattern="NP_TOSTRING_COULD_RETURN_NULL"/>
     </Match>
+
+ <!--
+ IMAPFolder.uidTable is only ever manipulated when the
+ messageCacheLock is held, but FindBugs can't figure that out.
+ -->
+ <Match>
+ <Class name="com.sun.mail.imap.IMAPFolder"/>
+ <Field name="uidTable"/>
+ <Bug pattern="IS2_INCONSISTENT_SYNC"/>
+ </Match>
+
+ <!--
+ IMAPFolder.doExpungeNotification is only ever manipulated when the
+ messageCacheLock is held, but FindBugs can't figure that out.
+ -->
+ <Match>
+ <Class name="com.sun.mail.imap.IMAPFolder"/>
+ <Field name="doExpungeNotification"/>
+ <Bug pattern="IS2_INCONSISTENT_SYNC"/>
+ </Match>
 </FindBugsFilter>


diff -r ce5c9e0d6532 -r f8d43a69cdc5 mail/src/main/java/com/sun/mail/pop3/POP3Store.java
--- a/mail/src/main/java/com/sun/mail/pop3/POP3Store.java Fri Feb 04 18:05:11 2011 -0800
+++ b/mail/src/main/java/com/sun/mail/pop3/POP3Store.java Mon Feb 07 22:30:09 2011 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
@@ -376,7 +376,10 @@
      * @since JavaMail 1.4.3
      */
     public Map capabilities() throws MessagingException {
- Map c = capabilities; // atomic read of pointer
+ Map c;
+ synchronized (this) {
+ c = capabilities;
+ }
         if (c != null)
             return Collections.unmodifiableMap(c);
         else


diff -r f8d43a69cdc5 -r e497aeaa91a6 mail/src/main/java/javax/mail/Multipart.java
--- a/mail/src/main/java/javax/mail/Multipart.java Mon Feb 07 22:30:09 2011 -0800
+++ b/mail/src/main/java/javax/mail/Multipart.java Mon Feb 07 22:51:13 2011 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
@@ -122,7 +122,7 @@
      * @return content-type
      * @see #contentType
      */
- public String getContentType() {
+ public synchronized String getContentType() {
         return contentType;
     }
 


diff -r e497aeaa91a6 -r 2c9b3c148355 mail/src/main/java/javax/mail/Folder.java
--- a/mail/src/main/java/javax/mail/Folder.java Mon Feb 07 22:51:13 2011 -0800
+++ b/mail/src/main/java/javax/mail/Folder.java Mon Feb 07 22:51:48 2011 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
@@ -637,7 +637,7 @@
      * @return the open mode of this folder
      * @since JavaMail 1.1
      */
- public int getMode() {
+ public synchronized int getMode() {
         if (!isOpen())
             throw new IllegalStateException("Folder not open");
         return mode;


diff -r 2c9b3c148355 -r 9286a20c5139 mail/src/main/java/com/sun/mail/pop3/POP3Message.java
--- a/mail/src/main/java/com/sun/mail/pop3/POP3Message.java Mon Feb 07 22:51:48 2011 -0800
+++ b/mail/src/main/java/com/sun/mail/pop3/POP3Message.java Tue Feb 08 14:12:48 2011 -0800
@@ -107,21 +107,32 @@
     public int getSize() throws MessagingException {
         try {
             synchronized (this) {
- if (msgSize < 0) {
- /*
- * Use LIST to determine the entire message
- * size and subtract out the header size
- * (which may involve loading the headers,
- * which may load the content as a side effect).
- * If the content is loaded as a side effect of
- * loading the headers, it will set the size.
- */
- if (headers == null)
- loadHeaders();
+ // if we already have the size, return it
+ if (msgSize > 0)
+ return msgSize;
+ }
 
- if (msgSize < 0)
- msgSize = folder.getProtocol().list(msgnum) - hdrSize;
- }
+ /*
+ * Use LIST to determine the entire message
+ * size and subtract out the header size
+ * (which may involve loading the headers,
+ * which may load the content as a side effect).
+ * If the content is loaded as a side effect of
+ * loading the headers, it will set the size.
+ *
+ * Make sure to call loadHeaders() outside of the
+ * synchronization block. There's a potential race
+ * condition here but synchronization will occur in
+ * loadHeaders() to make sure the headers are only
+ * loaded once, and again in the following block to
+ * only compute msgSize once.
+ */
+ if (headers == null)
+ loadHeaders();
+
+ synchronized (this) {
+ if (msgSize < 0)
+ msgSize = folder.getProtocol().list(msgnum) - hdrSize;
                 return msgSize;
             }
         } catch (EOFException eex) {
@@ -534,7 +545,9 @@
      * The headers are fetched using the POP3 TOP command.
      */
     private void loadHeaders() throws MessagingException {
+ assert !Thread.holdsLock(this);
         try {
+ boolean fetchContent = false;
             synchronized (this) {
                 if (headers != null) // check again under lock
                     return;
@@ -544,11 +557,34 @@
                     // possibly because the TOP command isn't supported,
                     // load headers as a side effect of loading the entire
                     // content.
- InputStream cs = getContentStream();
- cs.close();
+ fetchContent = true;
                 } else {
- hdrSize = hdrs.available();
- headers = new InternetHeaders(hdrs);
+ try {
+ hdrSize = hdrs.available();
+ headers = new InternetHeaders(hdrs);
+ } finally {
+ hdrs.close();
+ }
+ }
+ }
+
+ /*
+ * Outside the synchronization block...
+ *
+ * Do we need to fetch the entire mesage content in order to
+ * load the headers as a side effect? Yes, there's a race
+ * condition here - multiple threads could decide that the
+ * content needs to be fetched. Fortunately, they'll all
+ * synchronize in the getContentStream method and the content
+ * will only be loaded once.
+ */
+ if (fetchContent) {
+ InputStream cs = null;
+ try {
+ cs = getContentStream();
+ } finally {
+ if (cs != null)
+ cs.close();
                 }
             }
         } catch (EOFException eex) {


diff -r 9286a20c5139 -r 207e329deb09 mail/src/main/java/javax/mail/internet/MimeUtility.java
--- a/mail/src/main/java/javax/mail/internet/MimeUtility.java Tue Feb 08 14:12:48 2011 -0800
+++ b/mail/src/main/java/javax/mail/internet/MimeUtility.java Mon Feb 14 13:30:20 2011 -0800
@@ -252,7 +252,7 @@
             try {
                 byte[] b = "\r\n".getBytes(charset);
                 bool = Boolean.valueOf(
- b != null && b.length == 2 && b[0] == 015 && b[1] == 012);
+ b == null || b.length != 2 || b[0] != 015 || b[1] != 012);
             } catch (UnsupportedEncodingException uex) {
                 bool = Boolean.FALSE; // a guess
             } catch (RuntimeException ex) {

diff -r 9286a20c5139 -r 207e329deb09 mail/src/test/java/javax/mail/internet/MimeUtilityTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mail/src/test/java/javax/mail/internet/MimeUtilityTest.java Mon Feb 14 13:30:20 2011 -0800
@@ -0,0 +1,78 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
+ * and Distribution License("CDDL") (collectively, the "License"). You
+ * may not use this file except in compliance with the License. You can
+ * obtain a copy of the License at
+ * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
+ * or packager/legal/LICENSE.txt. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at packager/legal/LICENSE.txt.
+ *
+ * GPL Classpath Exception:
+ * Oracle designates th
[truncated due to length]