commits@javamail.java.net

[javamail~mercurial:691] CompactFormatter workaround for JDK-6282094.

From: <shannon_at_java.net>
Date: Wed, 18 Feb 2015 20:25:02 +0000

Project: javamail
Repository: mercurial
Revision: 691
Author: shannon
Date: 2015-02-18 18:58:43 UTC
Link:

Log Message:
------------
Synchronize requestPasswordAuthentication, for thread safety - bug 6703
CompactFormatter workaround for JDK-6282094.

CompactFormatterTest add tests for date/time conversions.

MailHandlerTest fix compile error on JDK5.

(From Jason)


Revisions:
----------
690
691


Modified Paths:
---------------
doc/release/CHANGES.txt
doc/release/COMPAT.txt
mail/src/main/java/javax/mail/Authenticator.java
mail/src/main/java/com/sun/mail/util/logging/CompactFormatter.java
mail/src/test/java/com/sun/mail/util/logging/CompactFormatterTest.java
mail/src/test/java/com/sun/mail/util/logging/MailHandlerTest.java


Diffs:
------
diff -r 2ab7ca2957c6 -r c48aa8d224e6 doc/release/CHANGES.txt
--- a/doc/release/CHANGES.txt Tue Feb 17 14:59:44 2015 -0800
+++ b/doc/release/CHANGES.txt Tue Feb 17 15:03:42 2015 -0800
@@ -33,6 +33,7 @@
 K 6667 MimeBodyPart with copied DataHandler doesn't always set encoding
 K 6668 skip unusable Store and Transport classes
 K 6687 long parameter values should be split using RFC 2231
+K 6703 javax.mail.Authenticator thread safety
 
 
                   CHANGES IN THE 1.5.2 RELEASE

diff -r 2ab7ca2957c6 -r c48aa8d224e6 doc/release/COMPAT.txt
--- a/doc/release/COMPAT.txt Tue Feb 17 14:59:44 2015 -0800
+++ b/doc/release/COMPAT.txt Tue Feb 17 15:03:42 2015 -0800
@@ -23,6 +23,15 @@
         has been fixed in the 1.5.3 release, but programs that accidentally
         relied on the old behavior may get different results.
 
+- Authenticator is now synchronized
+
+ The call to the Authenticator's getPasswordAuthentication method
+ is now synchronized so that the state stored in the Authenticator
+ is safe if multiple threads try to use the Authenticator
+ simultaneously. If the application's getPasswordAuthentication
+ method blocks, it will prevent other threads in the same
+ Session from using the Authenticator.
+
 
 
 -- JavaMail 1.5 --

diff -r 2ab7ca2957c6 -r c48aa8d224e6 mail/src/main/java/javax/mail/Authenticator.java
--- a/mail/src/main/java/javax/mail/Authenticator.java Tue Feb 17 14:59:44 2015 -0800
+++ b/mail/src/main/java/javax/mail/Authenticator.java Tue Feb 17 15:03:42 2015 -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-2015 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
@@ -101,7 +101,7 @@
      *
      * @return The username/password, or null if one can't be gotten.
      */
- final PasswordAuthentication requestPasswordAuthentication(
+ final synchronized PasswordAuthentication requestPasswordAuthentication(
                                 InetAddress addr, int port, String protocol,
                                 String prompt, String defaultUserName) {
 


diff -r c48aa8d224e6 -r 4a32d8901f79 mail/src/main/java/com/sun/mail/util/logging/CompactFormatter.java
--- a/mail/src/main/java/com/sun/mail/util/logging/CompactFormatter.java Tue Feb 17 15:03:42 2015 -0800
+++ b/mail/src/main/java/com/sun/mail/util/logging/CompactFormatter.java Wed Feb 18 10:58:43 2015 -0800
@@ -166,7 +166,11 @@
             new Alternate(msg, thrown),
             new Alternate(thrown, msg)};
 
- return String.format(l, fmt, params);
+ if (l == null) { //BUG ID 6282094
+ return String.format(fmt, params);
+ } else {
+ return String.format(l, fmt, params);
+ }
     }
 
     /**

diff -r c48aa8d224e6 -r 4a32d8901f79 mail/src/test/java/com/sun/mail/util/logging/CompactFormatterTest.java
--- a/mail/src/test/java/com/sun/mail/util/logging/CompactFormatterTest.java Tue Feb 17 15:03:42 2015 -0800
+++ b/mail/src/test/java/com/sun/mail/util/logging/CompactFormatterTest.java Wed Feb 18 10:58:43 2015 -0800
@@ -376,6 +376,55 @@
     }
 
     @Test
+ public void testFormatMillis() {
+ String p = "%1$tc";
+ CompactFormatter cf = new CompactFormatter(p);
+ LogRecord r = new LogRecord(Level.SEVERE, "");
+ assertEquals(String.format(p, r.getMillis()),
+ cf.format(r));
+ }
+
+ @Test
+ public void testFormatMillisLocale() throws Exception {
+ String p = "%1$tc";
+ CompactFormatter cf = new CompactFormatter(p);
+ Properties props = new Properties();
+ LogRecord r = new LogRecord(Level.SEVERE, "");
+ r.setResourceBundle(new LocaleResource(props, Locale.ENGLISH));
+ assertEquals(String.format(Locale.ENGLISH, p, r.getMillis()),
+ cf.format(r));
+ }
+
+ @Test
+ public void testFormatMillisByParts() {
+ String p = "%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp";
+ CompactFormatter cf = new CompactFormatter(p);
+ LogRecord r = new LogRecord(Level.SEVERE, "");
+ assertEquals(String.format(p, r.getMillis()),
+ cf.format(r));
+ }
+
+ @Test
+ public void testFormatMillisByPartsLocale() throws Exception {
+ String p = "%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp";
+ CompactFormatter cf = new CompactFormatter(p);
+ Properties props = new Properties();
+ LogRecord r = new LogRecord(Level.SEVERE, "");
+ r.setResourceBundle(new LocaleResource(props, Locale.ENGLISH));
+ assertEquals(String.format(Locale.ENGLISH, p, r.getMillis()),
+ cf.format(r));
+ }
+
+ @Test
+ public void testFormatMillisAsLong() {
+ String p = "%1$tQ";
+ CompactFormatter cf = new CompactFormatter(p);
+ LogRecord r = new LogRecord(Level.SEVERE, "");
+ assertEquals(String.format(p, r.getMillis()),
+ cf.format(r));
+ }
+
+ @Test
     public void testFormatSourceByLogger() {
         CompactFormatter cf = new CompactFormatter();
         LogRecord record = new LogRecord(Level.SEVERE, "");

diff -r c48aa8d224e6 -r 4a32d8901f79 mail/src/test/java/com/sun/mail/util/logging/MailHandlerTest.java
--- a/mail/src/test/java/com/sun/mail/util/logging/MailHandlerTest.java Tue Feb 17 15:03:42 2015 -0800
+++ b/mail/src/test/java/com/sun/mail/util/logging/MailHandlerTest.java Wed Feb 18 10:58:43 2015 -0800
@@ -7489,7 +7489,6 @@
             this.expect = expect;
         }
 
- @Override
         public int compare(LogRecord o1, LogRecord o2) {
             checkContextClassLoader(expect);
             return new SequenceComparator().compare(o1, o2);