diff --git a/java/src/main/java/org/rocksdb/ColumnFamilyHandle.java b/java/src/main/java/org/rocksdb/ColumnFamilyHandle.java index 9cda136b7..3a2e97efb 100644 --- a/java/src/main/java/org/rocksdb/ColumnFamilyHandle.java +++ b/java/src/main/java/org/rocksdb/ColumnFamilyHandle.java @@ -32,6 +32,7 @@ public class ColumnFamilyHandle extends RocksObject { * @throws RocksDBException if an error occurs whilst retrieving the name. */ public byte[] getName() throws RocksDBException { + assert(isOwningHandle() || isDefaultColumnFamily()); return getName(nativeHandle_); } @@ -41,6 +42,7 @@ public class ColumnFamilyHandle extends RocksObject { * @return the ID of the Column Family. */ public int getID() { + assert(isOwningHandle() || isDefaultColumnFamily()); return getID(nativeHandle_); } @@ -59,7 +61,7 @@ public class ColumnFamilyHandle extends RocksObject { * descriptor. */ public ColumnFamilyDescriptor getDescriptor() throws RocksDBException { - assert(isOwningHandle()); + assert(isOwningHandle() || isDefaultColumnFamily()); return getDescriptor(nativeHandle_); } @@ -91,6 +93,10 @@ public class ColumnFamilyHandle extends RocksObject { } } + protected boolean isDefaultColumnFamily() { + return nativeHandle_ == rocksDB_.getDefaultColumnFamily().nativeHandle_; + } + /** *
Deletes underlying C++ iterator pointer.
* diff --git a/java/src/test/java/org/rocksdb/ColumnFamilyTest.java b/java/src/test/java/org/rocksdb/ColumnFamilyTest.java index cc8199ec4..a9a087635 100644 --- a/java/src/test/java/org/rocksdb/ColumnFamilyTest.java +++ b/java/src/test/java/org/rocksdb/ColumnFamilyTest.java @@ -75,6 +75,7 @@ public class ColumnFamilyTest { assertThat(cfh.getName()).isEqualTo("default".getBytes(UTF_8)); assertThat(cfh.getID()).isEqualTo(0); + assertThat(cfh.getDescriptor().getName()).isEqualTo("default".getBytes(UTF_8)); final byte[] key = "key".getBytes(); final byte[] value = "value".getBytes();