diff --git a/src/main/java/com/couchbase/client/CouchbaseClient.java b/src/main/java/com/couchbase/client/CouchbaseClient.java index 0ffed969..a582bf77 100644 --- a/src/main/java/com/couchbase/client/CouchbaseClient.java +++ b/src/main/java/com/couchbase/client/CouchbaseClient.java @@ -1370,6 +1370,10 @@ public boolean shutdown(long timeout, TimeUnit unit) { * normally utilized through higher-level methods but can also be used * directly. * + * If persist is null, it will default to PersistTo.ZERO and if replicate is + * null, it will default to ReplicateTo.ZERO. This is the default behavior + * and is the same as not observing at all. + * * @param key the key to observe. * @param cas the CAS value for the key. * @param persist the persistence settings. @@ -1379,6 +1383,12 @@ public boolean shutdown(long timeout, TimeUnit unit) { public void observePoll(String key, long cas, PersistTo persist, ReplicateTo replicate, boolean isDelete) { boolean persistMaster = false; + if(persist == null) { + persist = PersistTo.ZERO; + } + if(replicate == null) { + replicate = ReplicateTo.ZERO; + } int persistReplica = persist.getValue(); int replicateTo = replicate.getValue(); int obsPolls = 0; diff --git a/src/test/java/com/couchbase/client/CouchbaseClientTest.java b/src/test/java/com/couchbase/client/CouchbaseClientTest.java index 441ad35f..a8f6f340 100644 --- a/src/test/java/com/couchbase/client/CouchbaseClientTest.java +++ b/src/test/java/com/couchbase/client/CouchbaseClientTest.java @@ -40,6 +40,8 @@ import net.spy.memcached.internal.OperationFuture; import org.junit.Ignore; +import static org.junit.Assert.assertTrue; + /** * A CouchbaseClientTest. */ @@ -219,6 +221,30 @@ public void testStatsKey() throws Exception { assertFalse(future.getStatus().isSuccess()); } + /** + * Tests if passing NULL for ReplicateTo and/or + * PersistTo correctly works and does not throw + * an exception. + */ + public void testNullObserve() throws Exception { + boolean success; + try { + success = true; + OperationFuture nullcheckOp = + (((CouchbaseClient)client).add("nullcheck", 0, "value", null, null)); + nullcheckOp.get(); + nullcheckOp = + (((CouchbaseClient)client).set("nullcheck", 0, "value1", null, null)); + nullcheckOp.get(); + nullcheckOp = + (((CouchbaseClient)client).replace("nullcheck", 0, "value1", null, null)); + nullcheckOp.get(); + } catch(NullPointerException ex) { + success = false; + } + assertTrue(success); + } + public void testGetStatsSlabs() throws Exception { // Empty }