DATACOUCH-53 - protection against NPE on CouchbaseCache when putting null as a value
This commit is contained in:
committed by
Michael Nitschinger
parent
7d79d79e28
commit
b11fc6c53c
@@ -88,8 +88,12 @@ public class CouchbaseCache implements Cache {
|
||||
* @param value the Object to store.
|
||||
*/
|
||||
public final void put(final Object key, final Object value) {
|
||||
String documentId = key.toString();
|
||||
client.set(documentId, 0, value);
|
||||
if (value != null) {
|
||||
String documentId = key.toString();
|
||||
client.set(documentId, 0, value);
|
||||
} else {
|
||||
evict(key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -97,4 +97,21 @@ public class CouchbaseCacheTests {
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Putting into cache on the same key not null value, and then null value,
|
||||
* results in null object
|
||||
*/
|
||||
@Test
|
||||
public void testSettingNullAndGetting() {
|
||||
CouchbaseCache cache = new CouchbaseCache(cacheName, client);
|
||||
|
||||
String key = "couchbase-cache-test";
|
||||
String value = "Hello World!";
|
||||
|
||||
cache.put(key, value);
|
||||
cache.put(key, null);
|
||||
|
||||
assertNull(cache.get(key));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user