You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2018/08/08 14:42:43 UTC

httpcomponents-client git commit: Fix HttpClient 4.5.4 regression in BasicCookieStore serialization.

Repository: httpcomponents-client
Updated Branches:
  refs/heads/4.6.x 348661077 -> 7a4f9bc7a


Fix HttpClient 4.5.4 regression in BasicCookieStore serialization.

HttpClient 4.5.4 modified BasicCookieStore to introduce a new
ReadWriteLock field to improve performance. Unfortunately this
also changed the serialized data structure, and any objects
serialized using HttpClient 4.5.3 and before would be unusable
after restore in HttpClient 4.5.4 due to the new "lock" field
being null.

The fix is to change "lock" to be transient, and ensure it is
correctly instantiated upon object restore. This restores
compatibility with HttpClient 4.5.3, as well as maintaining
compatible with the intermediate versions containing the
regression. This also avoids unnecessary serialization of
the new "lock" field, which does not need to be persisted.


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/7a4f9bc7
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/7a4f9bc7
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/7a4f9bc7

Branch: refs/heads/4.6.x
Commit: 7a4f9bc7af8e1849586511e401f7559f34892992
Parents: 3486610
Author: Mark Mielke <mm...@ciena.com>
Authored: Wed Aug 8 06:43:55 2018 -0400
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Wed Aug 8 16:40:53 2018 +0200

----------------------------------------------------------------------
 .../org/apache/http/impl/client/BasicCookieStore.java    | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/7a4f9bc7/httpclient/src/main/java/org/apache/http/impl/client/BasicCookieStore.java
----------------------------------------------------------------------
diff --git a/httpclient/src/main/java/org/apache/http/impl/client/BasicCookieStore.java b/httpclient/src/main/java/org/apache/http/impl/client/BasicCookieStore.java
index c536c6e..6f81a22 100644
--- a/httpclient/src/main/java/org/apache/http/impl/client/BasicCookieStore.java
+++ b/httpclient/src/main/java/org/apache/http/impl/client/BasicCookieStore.java
@@ -26,6 +26,8 @@
  */
 package org.apache.http.impl.client;
 
+import java.io.IOException;
+import java.io.ObjectInputStream;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Date;
@@ -53,7 +55,7 @@ public class BasicCookieStore implements CookieStore, Serializable {
     private static final long serialVersionUID = -7581093305228232025L;
 
     private final TreeSet<Cookie> cookies;
-    private final ReadWriteLock lock;
+    private transient ReadWriteLock lock;
 
     public BasicCookieStore() {
         super();
@@ -61,6 +63,13 @@ public class BasicCookieStore implements CookieStore, Serializable {
         this.lock = new ReentrantReadWriteLock();
     }
 
+    private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
+        stream.defaultReadObject();
+
+        /* Reinstantiate transient fields. */
+        this.lock = new ReentrantReadWriteLock();
+    }
+
     /**
      * Adds an {@link Cookie HTTP cookie}, replacing any existing equivalent cookies.
      * If the given cookie has already expired it will not be added, but existing