diff --git a/java/org/rocksdb/ReadOptions.java b/java/org/rocksdb/ReadOptions.java index 5db616eba..aa6977e98 100644 --- a/java/org/rocksdb/ReadOptions.java +++ b/java/org/rocksdb/ReadOptions.java @@ -92,7 +92,11 @@ public class ReadOptions extends RocksObject { */ public ReadOptions setSnapshot(Snapshot snapshot) { assert(isInitialized()); - setSnapshot(nativeHandle_, snapshot.nativeHandle_); + if (snapshot != null) { + setSnapshot(nativeHandle_, snapshot.nativeHandle_); + } else { + setSnapshot(nativeHandle_, 0l); + } return this; } private native void setSnapshot(long handle, long snapshotHandle); diff --git a/java/org/rocksdb/test/SnapshotTest.java b/java/org/rocksdb/test/SnapshotTest.java index 7ff1637e3..67d0a83ef 100644 --- a/java/org/rocksdb/test/SnapshotTest.java +++ b/java/org/rocksdb/test/SnapshotTest.java @@ -69,6 +69,11 @@ public class SnapshotTest // null assert(db.get(readOptions, "newkey".getBytes()) == null); + // setting null to snapshot in ReadOptions leads + // to no Snapshot being used. + readOptions.setSnapshot(null); + assert(new String(db.get(readOptions, + "newkey".getBytes())).equals("newvalue")); // release Snapshot db.releaseSnapshot(snapshot); // Close database