hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1229169 - /httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/MemcachedHttpCacheStorage.java
Date Mon, 09 Jan 2012 14:28:39 GMT
Author: jonm
Date: Mon Jan  9 14:28:38 2012
New Revision: 1229169

URL: http://svn.apache.org/viewvc?rev=1229169&view=rev
Log:
HTTPCLIENT-1152: MemcachedHttpCacheStorage should verify class of returned
object before casting. Contributed by Rajika Kumarasiri <rajika at wso2 dot com>.

Modified:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/MemcachedHttpCacheStorage.java

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/MemcachedHttpCacheStorage.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/MemcachedHttpCacheStorage.java?rev=1229169&r1=1229168&r2=1229169&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/MemcachedHttpCacheStorage.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/MemcachedHttpCacheStorage.java
Mon Jan  9 14:28:38 2012
@@ -84,7 +84,7 @@ public class MemcachedHttpCacheStorage i
      * just have a single local memcached instance running on the same
      * machine as your application, for example.
      * @param address where the <i>memcached</i> daemon is running
-     * @throws IOException
+     * @throws IOException in case of an error
      */
     public MemcachedHttpCacheStorage(InetSocketAddress address) throws IOException {
         this(new MemcachedClient(address));
@@ -138,32 +138,33 @@ public class MemcachedHttpCacheStorage i
     public void updateEntry(String url, HttpCacheUpdateCallback callback)
             throws HttpCacheUpdateException, IOException {
         int numRetries = 0;
-        do{
+        do {
 
-        CASValue<Object> v = client.gets(url);
-        byte[] oldBytes = (v != null) ? (byte[]) v.getValue() : null;
-        HttpCacheEntry existingEntry = null;
-        if (oldBytes != null) {
-            ByteArrayInputStream bis = new ByteArrayInputStream(oldBytes);
-            existingEntry = serializer.readFrom(bis);
-        }
-        HttpCacheEntry updatedEntry = callback.update(existingEntry);
-
-        if (v == null) {
-            putEntry(url, updatedEntry);
-            return;
-
-        } else {
-            ByteArrayOutputStream bos = new ByteArrayOutputStream();
-            serializer.writeTo(updatedEntry, bos);
-            CASResponse casResult = client.cas(url, v.getCas(), bos.toByteArray());
-            if (casResult != CASResponse.OK) {
-                 numRetries++;
+            CASValue<Object> v = client.gets(url);
+            byte[] oldBytes = (v != null && (v.getValue() instanceof byte[])) ? (byte[])
v.getValue() :
+                    null;
+            HttpCacheEntry existingEntry = null;
+            if (oldBytes != null) {
+                ByteArrayInputStream bis = new ByteArrayInputStream(oldBytes);
+                existingEntry = serializer.readFrom(bis);
             }
-            else return;
-        }
+            HttpCacheEntry updatedEntry = callback.update(existingEntry);
 
-    } while(numRetries <= maxUpdateRetries);
-    throw new HttpCacheUpdateException("Failed to update");
+            if (v == null) {
+                putEntry(url, updatedEntry);
+                return;
+
+            } else {
+                ByteArrayOutputStream bos = new ByteArrayOutputStream();
+                serializer.writeTo(updatedEntry, bos);
+                CASResponse casResult = client.cas(url, v.getCas(), bos.toByteArray());
+                if (casResult != CASResponse.OK) {
+                    numRetries++;
+                } else return;
+            }
+
+        } while (numRetries <= maxUpdateRetries);
+
+        throw new HttpCacheUpdateException("Failed to update");
     }
 }



Mime
View raw message