Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49972
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 7 Oct 2010 14:05:51 +0000 (14:05 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 7 Oct 2010 14:05:51 +0000 (14:05 +0000)
Address potential thread safety issues.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1005452 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/tomcat/util/http/FastHttpDateFormat.java

index 0409c1f..fa16d32 100644 (file)
@@ -36,28 +36,28 @@ public final class FastHttpDateFormat {
     // -------------------------------------------------------------- Variables
 
 
-    protected static final int CACHE_SIZE = 
+    private static final int CACHE_SIZE = 
         Integer.parseInt(System.getProperty("org.apache.tomcat.util.http.FastHttpDateFormat.CACHE_SIZE", "1000"));
 
     
     /**
      * HTTP date format.
      */
-    protected static final SimpleDateFormat format = 
+    private static final SimpleDateFormat format = 
         new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
 
 
     /**
      * The set of SimpleDateFormat formats to use in getDateHeader().
      */
-    protected static final SimpleDateFormat formats[] = {
+    private static final SimpleDateFormat formats[] = {
         new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),
         new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
         new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US)
     };
 
 
-    protected final static TimeZone gmtZone = TimeZone.getTimeZone("GMT");
+    private static final TimeZone gmtZone = TimeZone.getTimeZone("GMT");
 
 
     /**
@@ -77,26 +77,26 @@ public final class FastHttpDateFormat {
     /**
      * Instant on which the currentDate object was generated.
      */
-    protected static long currentDateGenerated = 0L;
+    private static volatile long currentDateGenerated = 0L;
 
 
     /**
      * Current formatted date.
      */
-    protected static String currentDate = null;
+    private static String currentDate = null;
 
 
     /**
      * Formatter cache.
      */
-    protected static final ConcurrentHashMap<Long, String> formatCache = 
+    private static final ConcurrentHashMap<Long, String> formatCache = 
         new ConcurrentHashMap<Long, String>(CACHE_SIZE);
 
 
     /**
      * Parser cache.
      */
-    protected static final ConcurrentHashMap<String, Long> parseCache = 
+    private static final ConcurrentHashMap<String, Long> parseCache = 
         new ConcurrentHashMap<String, Long>(CACHE_SIZE);
 
 
@@ -112,8 +112,8 @@ public final class FastHttpDateFormat {
         if ((now - currentDateGenerated) > 1000) {
             synchronized (format) {
                 if ((now - currentDateGenerated) > 1000) {
-                    currentDateGenerated = now;
                     currentDate = format.format(new Date(now));
+                    currentDateGenerated = now;
                 }
             }
         }