From 9f0bc2474fed55c3e1a5f770f7e7c45bf30aa244 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Date: Mon, 9 Jan 2012 14:33:08 +0000 Subject: [PATCH] HTTPCLIENT-1152: Log a WARN-level message if memcached gives us back something other than a byte[]. git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1229172 13f79535-47bb-0310-9956-ffa450edef68 --- .../cache/memcached/MemcachedHttpCacheStorage.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/MemcachedHttpCacheStorage.java b/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/MemcachedHttpCacheStorage.java index 3eb134a69..5ebb15f56 100644 --- a/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/MemcachedHttpCacheStorage.java +++ b/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/MemcachedHttpCacheStorage.java @@ -37,6 +37,8 @@ import net.spy.memcached.CASValue; import net.spy.memcached.MemcachedClient; import net.spy.memcached.MemcachedClientIF; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.http.client.cache.HttpCacheEntry; import org.apache.http.client.cache.HttpCacheEntrySerializer; import org.apache.http.client.cache.HttpCacheUpdateException; @@ -74,6 +76,8 @@ import org.apache.http.impl.client.cache.DefaultHttpCacheEntrySerializer; */ public class MemcachedHttpCacheStorage implements HttpCacheStorage { + private static final Log log = LogFactory.getLog(MemcachedHttpCacheStorage.class); + private final MemcachedClientIF client; private final HttpCacheEntrySerializer serializer; private final int maxUpdateRetries; @@ -141,8 +145,14 @@ public class MemcachedHttpCacheStorage implements HttpCacheStorage { do { CASValue v = client.gets(url); - byte[] oldBytes = (v != null && (v.getValue() instanceof byte[])) ? (byte[]) v.getValue() : - null; + byte[] oldBytes = null; + if (v != null) { + if (v.getValue() instanceof byte[]) { + oldBytes = (byte[])v.getValue(); + } else { + log.warn("got non-bytearray back from memcached"); + } + } HttpCacheEntry existingEntry = null; if (oldBytes != null) { ByteArrayInputStream bis = new ByteArrayInputStream(oldBytes);