hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r967227 - in /httpcomponents/httpclient/trunk: RELEASE_NOTES.txt httpclient/src/main/java/org/apache/http/impl/client/BasicCookieStore.java
Date Fri, 23 Jul 2010 19:45:47 GMT
Author: olegk
Date: Fri Jul 23 19:45:47 2010
New Revision: 967227

URL: http://svn.apache.org/viewvc?rev=967227&view=rev
Log:
HTTPCLIENT-969: BasicCookieStore#getCookies() to return a copy of Cookie list 
Contributed by David Smiley <dsmiley at mitre.org>

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/BasicCookieStore.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=967227&r1=967226&r2=967227&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Fri Jul 23 19:45:47 2010
@@ -1,6 +1,9 @@
 Changes since 4.1 ALPHA2
 -------------------
 
+* [HTTPCLIENT-969] BasicCookieStore#getCookies() to return a copy of Cookie list 
+  Contributed by David Smiley <dsmiley at mitre.org>
+
 * [HTTPCLIENT-965] Fixed problem with cache not honoring must-revalidate or 
   proxy-revalidate Cache-Control directives.
   Contributed by Jonathan Moore <jonathan_moore at comcast.com>

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/BasicCookieStore.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/BasicCookieStore.java?rev=967227&r1=967226&r2=967227&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/BasicCookieStore.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/BasicCookieStore.java
Fri Jul 23 19:45:47 2010
@@ -27,12 +27,7 @@
 package org.apache.http.impl.client;
 
 import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
 
 import org.apache.http.annotation.GuardedBy;
 import org.apache.http.annotation.ThreadSafe;
@@ -50,23 +45,14 @@ import org.apache.http.cookie.CookieIden
 @ThreadSafe
 public class BasicCookieStore implements CookieStore, Serializable {
 
-    private static final long serialVersionUID = -1113466491038527240L;
+    private static final long serialVersionUID = -7581093305228232025L;
 
     @GuardedBy("this")
-    private final ArrayList<Cookie> cookies;
+    private final TreeSet<Cookie> cookies;
 
-    @GuardedBy("this")
-    private final Comparator<Cookie> cookieComparator;
-
-    // -------------------------------------------------------- Class Variables
-
-    /**
-     * Default constructor.
-     */
     public BasicCookieStore() {
         super();
-        this.cookies = new ArrayList<Cookie>();
-        this.cookieComparator = new CookieIdentityComparator();
+        this.cookies = new TreeSet<Cookie>(new CookieIdentityComparator());
     }
 
     /**
@@ -82,12 +68,7 @@ public class BasicCookieStore implements
     public synchronized void addCookie(Cookie cookie) {
         if (cookie != null) {
             // first remove any old cookie that is equivalent
-            for (Iterator<Cookie> it = cookies.iterator(); it.hasNext();) {
-                if (cookieComparator.compare(cookie, it.next()) == 0) {
-                    it.remove();
-                    break;
-                }
-            }
+            cookies.remove(cookie);
             if (!cookie.isExpired(new Date())) {
                 cookies.add(cookie);
             }
@@ -119,7 +100,8 @@ public class BasicCookieStore implements
      * @return an array of {@link Cookie cookies}.
      */
     public synchronized List<Cookie> getCookies() {
-        return Collections.unmodifiableList(this.cookies);
+        //create defensive copy so it won't be concurrently modified
+        return new ArrayList<Cookie>(cookies);
     }
 
     /**
@@ -144,11 +126,6 @@ public class BasicCookieStore implements
         return removed;
     }
 
-    @Override
-    public String toString() {
-        return cookies.toString();
-    }
-
     /**
      * Clears all cookies.
      */
@@ -156,4 +133,9 @@ public class BasicCookieStore implements
         cookies.clear();
     }
 
+    @Override
+    public synchronized String toString() {
+        return cookies.toString();
+    }
+
 }



Mime
View raw message