6965924: java.net.HttpCookie using static SimpleDateFormat which is not thread safe
authorchegar
Mon, 23 Aug 2010 16:27:56 +0100
changeset 6317 8046f5f96da1
parent 6316 6d91c1ceac26
child 6318 b279b6772e21
6965924: java.net.HttpCookie using static SimpleDateFormat which is not thread safe Reviewed-by: michaelm
jdk/src/share/classes/java/net/HttpCookie.java
--- a/jdk/src/share/classes/java/net/HttpCookie.java	Mon Aug 23 14:35:22 2010 +0100
+++ b/jdk/src/share/classes/java/net/HttpCookie.java	Mon Aug 23 16:27:56 2010 +0100
@@ -1093,14 +1093,8 @@
         return sb.toString();
     }
 
-    private static SimpleDateFormat[] cDateFormats = null;
-    static {
-            cDateFormats = new SimpleDateFormat[COOKIE_DATE_FORMATS.length];
-            for (int i = 0; i < COOKIE_DATE_FORMATS.length; i++) {
-                cDateFormats[i] = new SimpleDateFormat(COOKIE_DATE_FORMATS[i], Locale.US);
-                cDateFormats[i].setTimeZone(TimeZone.getTimeZone("GMT"));
-            }
-    }
+    static final TimeZone GMT = TimeZone.getTimeZone("GMT");
+
     /*
      * @param dateString        a date string in one of the formats
      *                          defined in Netscape cookie spec
@@ -1109,12 +1103,14 @@
      *                          time and the time specified by dateString
      */
     private long expiryDate2DeltaSeconds(String dateString) {
-        for (SimpleDateFormat df : cDateFormats) {
+        for (int i = 0; i < COOKIE_DATE_FORMATS.length; i++) {
+            SimpleDateFormat df = new SimpleDateFormat(COOKIE_DATE_FORMATS[i], Locale.US);
+            df.setTimeZone(GMT);
             try {
                 Date date = df.parse(dateString);
                 return (date.getTime() - whenCreated) / 1000;
             } catch (Exception e) {
-
+                // Ignore, try the next date format
             }
         }
         return 0;