Author: markt
Date: Wed Jun  3 21:59:02 2009
New Revision: 781598

URL: http://svn.apache.org/viewvc?rev=781598&view=rev
Log:
Make DateTool thread safe. Patch by fhanik.

Modified:
    tomcat/connectors/trunk/util/java/org/apache/tomcat/util/buf/DateTool.java
    tomcat/container/tc5.5.x/webapps/docs/changelog.xml

Modified: 
tomcat/connectors/trunk/util/java/org/apache/tomcat/util/buf/DateTool.java
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/util/java/org/apache/tomcat/util/buf/DateTool.java?rev=781598&r1=781597&r2=781598&view=diff
==============================================================================
--- tomcat/connectors/trunk/util/java/org/apache/tomcat/util/buf/DateTool.java 
(original)
+++ tomcat/connectors/trunk/util/java/org/apache/tomcat/util/buf/DateTool.java 
Wed Jun  3 21:59:02 2009
@@ -66,28 +66,42 @@
 
     /** DateFormat to be used to format dates. Called from MessageBytes
      */
-    private final static DateFormat rfc1123Format =
-       new SimpleDateFormat(RFC1123_PATTERN, LOCALE_US);
+    private final static ThreadLocal<DateFormat> rfc1123Format = new 
ThreadLocal<DateFormat>() {
+        public DateFormat initialValue() {
+            DateFormat result = new SimpleDateFormat(RFC1123_PATTERN, 
LOCALE_US);
+            result.setTimeZone(GMT_ZONE);
+            return result;
+        }
+    };
     
     /** DateFormat to be used to format old netscape cookies
        Called from ServerCookie
      */
-    private final static DateFormat oldCookieFormat =
-       new SimpleDateFormat(OLD_COOKIE_PATTERN, LOCALE_US);
-    
-    private final static DateFormat rfc1036Format =
-       new SimpleDateFormat(rfc1036Pattern, LOCALE_US);
+    private final static ThreadLocal<DateFormat> oldCookieFormat = new 
ThreadLocal<DateFormat>() {
+        public DateFormat initialValue() {
+            DateFormat result = new SimpleDateFormat(OLD_COOKIE_PATTERN, 
LOCALE_US);
+            result.setTimeZone(GMT_ZONE);
+            return result;
+        }
+    };
+
     
-    private final static DateFormat asctimeFormat =
-       new SimpleDateFormat(asctimePattern, LOCALE_US);
+    private final static ThreadLocal<DateFormat> rfc1036Format = new 
ThreadLocal<DateFormat>() {
+        public DateFormat initialValue() {
+            DateFormat result = new SimpleDateFormat(rfc1036Pattern, 
LOCALE_US);
+            result.setTimeZone(GMT_ZONE);
+            return result;
+        }
+    };
+
+    private final static ThreadLocal<DateFormat> asctimeFormat = new 
ThreadLocal<DateFormat>() {
+        public DateFormat initialValue() {
+            DateFormat result = new SimpleDateFormat(asctimePattern, 
LOCALE_US);
+            result.setTimeZone(GMT_ZONE);
+            return result;
+        }
+    };
     
-    static {
-       rfc1123Format.setTimeZone(GMT_ZONE);
-       oldCookieFormat.setTimeZone(GMT_ZONE);
-       rfc1036Format.setTimeZone(GMT_ZONE);
-       asctimeFormat.setTimeZone(GMT_ZONE);
-    }
- 
     private static String rfc1123DS;
     private static long   rfc1123Sec;
 
@@ -104,9 +118,7 @@
      */
     public static String format1123( Date d ) {
        String dstr=null;
-       synchronized(rfc1123Format) {
-           dstr = format1123(d, rfc1123Format);
-       }
+           dstr = format1123(d, rfc1123Format.get());
        return dstr;
     } 
 
@@ -126,18 +138,14 @@
     public static void formatOldCookie( Date d, StringBuffer sb,
                                          FieldPosition fp )
     {
-       synchronized(oldCookieFormat) {
-           oldCookieFormat.format( d, sb, fp );
-       }
+           oldCookieFormat.get().format( d, sb, fp );
     }
 
     // Called from ServerCookie
     public static String formatOldCookie( Date d )
     {
        String ocf=null;
-       synchronized(oldCookieFormat) {
-           ocf= oldCookieFormat.format( d );
-       }
+           ocf= oldCookieFormat.get().format( d );
        return ocf;
     }
 
@@ -146,7 +154,7 @@
        Not efficient - but not very used.
      */
     public static long parseDate( String dateString ) {
-       DateFormat [] format = {rfc1123Format,rfc1036Format,asctimeFormat};
+       DateFormat [] format = 
{rfc1123Format.get(),rfc1036Format.get(),asctimeFormat.get()};
        return parseDate(dateString,format);
     }
     public static long parseDate( String dateString, DateFormat []format ) {

Modified: tomcat/container/tc5.5.x/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/webapps/docs/changelog.xml?rev=781598&r1=781597&r2=781598&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/webapps/docs/changelog.xml (original)
+++ tomcat/container/tc5.5.x/webapps/docs/changelog.xml Wed Jun  3 21:59:02 2009
@@ -175,6 +175,9 @@
         Correct potential DOS issue in Java AJP connector when processing
         invalid request headers. This is CVE-2009-0033. (markt)
       </fix>
+      <fix>
+        Make DateTool thread safe. (fhanik) 
+      </fix>
     </changelog>
   </subsection>
 </section>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to