Author: markt
Date: Mon Oct 27 05:56:37 2008
New Revision: 708160

URL: http://svn.apache.org/viewvc?rev=708160&view=rev
Log:
Fix some thread safety issues in date formatting.

Modified:
    tomcat/tc6.0.x/trunk/STATUS.txt
    
tomcat/tc6.0.x/trunk/java/org/apache/catalina/ssi/ResponseIncludeWrapper.java
    tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/MessageBytes.java
    tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/http/ServerCookie.java
    tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml

Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=708160&r1=708159&r2=708160&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Mon Oct 27 05:56:37 2008
@@ -166,13 +166,6 @@
         }
         StringBuffer sb = new StringBuffer();
 
-* Fix some thread safety issues.
-  Deprecate (rather than delete) any deleted code that isn't already deprecated
-  http://svn.apache.org/viewvc?rev=699714&view=rev (previous patch)
-  http://svn.apache.org/viewvc?rev=700167&view=rev (additional changes)
-  +1: mark, remm,fhanik
-  -1: 
-
 * Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=45933
   Don't use xml parser from web-app to process tld files
   http://svn.apache.org/viewvc?rev=701355&view=rev

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/ssi/ResponseIncludeWrapper.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/ssi/ResponseIncludeWrapper.java?rev=708160&r1=708159&r2=708160&view=diff
==============================================================================
--- 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/ssi/ResponseIncludeWrapper.java 
(original)
+++ 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/ssi/ResponseIncludeWrapper.java 
Mon Oct 27 05:56:37 2008
@@ -20,6 +20,10 @@
 import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Locale;
+import java.util.TimeZone;
 
 import javax.servlet.ServletContext;
 import javax.servlet.ServletOutputStream;
@@ -27,7 +31,6 @@
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponseWrapper;
 
-import org.apache.catalina.util.DateTool;
 /**
  * A HttpServletResponseWrapper, used from
  * <code>SSIServletExternalResolver</code>
@@ -42,6 +45,9 @@
      */
     private static final String CONTENT_TYPE = "content-type";
     private static final String LAST_MODIFIED = "last-modified";
+    private static final DateFormat RFC1123_FORMAT;
+    private final static String RFC1123_PATTERN = "EEE, dd MMM yyyy HH:mm:ss 
z";
+
     protected long lastModified = -1;
     private String contentType = null;
 
@@ -55,7 +61,11 @@
     private ServletContext context;
     private HttpServletRequest request;
 
-
+    static {
+        RFC1123_FORMAT = new SimpleDateFormat(RFC1123_PATTERN, Locale.US);
+        RFC1123_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
+    }
+    
     /**
      * Initialize our wrapper with the current HttpServletResponse and
      * ServletOutputStream.
@@ -208,7 +218,9 @@
         String lname = name.toLowerCase();
         if (lname.equals(LAST_MODIFIED)) {
             try {
-                lastModified = DateTool.rfc1123Format.parse(value).getTime();
+                synchronized(RFC1123_FORMAT) {
+                    lastModified = RFC1123_FORMAT.parse(value).getTime();
+                }
             } catch (Throwable ignore) { }
         } else if (lname.equals(CONTENT_TYPE)) {
             contentType = value;
@@ -228,7 +240,9 @@
         String lname = name.toLowerCase();
         if (lname.equals(LAST_MODIFIED)) {
             try {
-                lastModified = DateTool.rfc1123Format.parse(value).getTime();
+                synchronized(RFC1123_FORMAT) {
+                    lastModified = RFC1123_FORMAT.parse(value).getTime();
+                }
             } catch (Throwable ignore) { }
         }
         else if (lname.equals(CONTENT_TYPE))

Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/MessageBytes.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/MessageBytes.java?rev=708160&r1=708159&r2=708160&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/MessageBytes.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/MessageBytes.java Mon 
Oct 27 05:56:37 2008
@@ -568,6 +568,9 @@
        type=T_STR;   
     }
 
+    /**
+     * @deprecated
+     */
     public void setTime(long t) {
        setTime( t, null );
     }

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/http/ServerCookie.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/http/ServerCookie.java?rev=708160&r1=708159&r2=708160&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/http/ServerCookie.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/http/ServerCookie.java Mon 
Oct 27 05:56:37 2008
@@ -18,11 +18,14 @@
 package org.apache.tomcat.util.http;
 
 import java.io.Serializable;
+import java.text.DateFormat;
 import java.text.FieldPosition;
+import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
 
 import org.apache.tomcat.util.buf.ByteChunk;
-import org.apache.tomcat.util.buf.DateTool;
 import org.apache.tomcat.util.buf.MessageBytes;
 
 
@@ -51,6 +54,19 @@
     private int maxAge = -1;
     private int version = 0;
 
+    // Other fields
+    private static final String OLD_COOKIE_PATTERN =
+        "EEE, dd-MMM-yyyy HH:mm:ss z";
+    private static final DateFormat OLD_COOKIE_FORMAT;
+    private static final String ancientDate;
+
+
+    static {
+        OLD_COOKIE_FORMAT = new SimpleDateFormat(OLD_COOKIE_PATTERN, 
Locale.US);
+        OLD_COOKIE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
+        ancientDate = OLD_COOKIE_FORMAT.format(new Date(10000));
+    }
+
     /**
      * If set to true, we parse cookies according to the servlet spec,
      */
@@ -245,9 +261,6 @@
         }
     }
 
-    private static final String ancientDate =
-        DateTool.formatOldCookie(new Date(10000));
-
     // TODO RFC2965 fields also need to be passed
     public static void appendCookieValue( StringBuffer headerBuf,
                                           int version,
@@ -295,10 +308,12 @@
                 if (maxAge == 0)
                     buf.append( ancientDate );
                 else
-                    DateTool.formatOldCookie
-                        (new Date( System.currentTimeMillis() +
-                                   maxAge *1000L), buf,
-                         new FieldPosition(0));
+                    synchronized (OLD_COOKIE_FORMAT) {
+                        OLD_COOKIE_FORMAT.format(
+                                new Date(System.currentTimeMillis() +
+                                        maxAge*1000L),
+                                buf, new FieldPosition(0));
+                    }
 
             } else {
                 buf.append ("; Max-Age=");

Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=708160&r1=708159&r2=708160&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Mon Oct 27 05:56:37 2008
@@ -117,6 +117,9 @@
       <fix>
         Fix cast error in JULI log factory. (markt)
       </fix>
+      <fix>
+        Fix some thread safety issues in date formatting. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to