HTTPCLIENT-1152: MemcachedHttpCacheStorage should verify class of returned

object before casting. Contributed by Rajika Kumarasiri <rajika at wso2 dot com>.


git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1229169 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Moore 2012-01-09 14:28:38 +00:00
parent 46bcf3acf7
commit a6fe2177be

View File

@ -84,7 +84,7 @@ public class MemcachedHttpCacheStorage implements HttpCacheStorage {
* 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,10 +138,11 @@ public void removeEntry(String url) throws IOException {
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;
byte[] oldBytes = (v != null && (v.getValue() instanceof byte[])) ? (byte[]) v.getValue() :
null;
HttpCacheEntry existingEntry = null;
if (oldBytes != null) {
ByteArrayInputStream bis = new ByteArrayInputStream(oldBytes);
@ -159,11 +160,11 @@ public void updateEntry(String url, HttpCacheUpdateCallback callback)
CASResponse casResult = client.cas(url, v.getCas(), bos.toByteArray());
if (casResult != CASResponse.OK) {
numRetries++;
}
else return;
} else return;
}
} while(numRetries <= maxUpdateRetries);
} while (numRetries <= maxUpdateRetries);
throw new HttpCacheUpdateException("Failed to update");
}
}