From 456461b1c62bc78d6006daec958f2bfb3e835893 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Wed, 17 Apr 2013 10:18:48 +0000 Subject: [PATCH] HTTPCLIENT-1299: (regression) cache incorrectly disposes of the underlying cache resource when storing variant entry (follow-up) Contributed by James Leigh git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1468823 13f79535-47bb-0310-9956-ffa450edef68 --- RELEASE_NOTES.txt | 4 ++++ .../org/apache/http/impl/client/cache/BasicHttpCache.java | 5 ++--- .../org/apache/http/impl/client/cache/CacheEntryUpdater.java | 4 +--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index b82c904f7..53e660fe5 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,6 +1,10 @@ Changes since release 4.3 BETA1 ------------------- +* [HTTPCLIENT-1299] (regression) cache incorrectly disposes of the underlying cache resource + when storing variant entry. + Contributed by James Leigh + * [HTTPCLIENT-1342] Redirects with underscore character in the location hostname cause "java.lang.IllegalArgumentException: Host name may not be null". Contributed by Oleg Kalnichevski diff --git a/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java b/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java index e6eb9e03e..1a2fd7674 100644 --- a/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java +++ b/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java @@ -199,10 +199,9 @@ class BasicHttpCache implements HttpCache { src = entry; } - final Resource oldResource = entry.getResource(); Resource resource = null; - if (oldResource != null) { - resource = resourceFactory.copy(requestId, entry.getResource()); + if (src.getResource() != null) { + resource = resourceFactory.copy(requestId, src.getResource()); } final Map variantMap = new HashMap(src.getVariantMap()); variantMap.put(variantKey, variantCacheKey); diff --git a/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java b/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java index 00d5c5565..ffc528b3c 100644 --- a/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java +++ b/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java @@ -87,11 +87,9 @@ class CacheEntryUpdater { Args.check(response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_MODIFIED, "Response must have 304 status code"); final Header[] mergedHeaders = mergeHeaders(entry, response); - final Resource oldResource = entry.getResource(); Resource resource = null; - if (oldResource != null) { + if (entry.getResource() != null) { resource = resourceFactory.copy(requestId, entry.getResource()); - oldResource.dispose(); } return new HttpCacheEntry( requestDate,