LevelDB implements AutoCloseable { public void put(byte[] key, byte[] value, LevelDBWriteOptions writeOptions) { checkDatabaseOpen(); writeOptions.checkWriteOptionsOpen(); PointerByReference error = new PointerByReference(); if (Native.POINTER_SIZE == 8) { long keyLength = key != null ? key.length : 0; long valueLength = value != null ? value.length : 0; LevelDBNative.leveldb_put(levelDB, writeOptions.writeOptions, key, keyLength, value, valueLength, error); } else { int keyLength = key != null ? key.length : 0; int valueLength = value != null ? value.length : 0; LevelDBNative.leveldb_put(levelDB, writeOptions.writeOptions, key, keyLength, value, valueLength, error); } LevelDBNative.checkError(error); } LevelDB(String levelDBDirectory, LevelDBOptions options); void close(); byte[] get(byte[] key, LevelDBReadOptions readOptions); void put(byte[] key, byte[] value, LevelDBWriteOptions writeOptions); void write(LevelDBWriteBatch writeBatch, LevelDBWriteOptions writeOptions); void delete(byte[] key, LevelDBWriteOptions writeOptions); String property(String property); long[] approximateSizes(Range ...ranges); void compactRange(byte[] startKey, byte[] limitKey); static void repair(String levelDBDirectory, LevelDBOptions options); static void destroy(String levelDBDirectory, LevelDBOptions options); static int majorVersion(); static int minorVersion();  }
@Test public void put_null_key() { try(LevelDBOptions options = new LevelDBOptions()) { options.setCreateIfMissing(true); try(LevelDBWriteOptions writeOptions = new LevelDBWriteOptions()) { try (LevelDB levelDB = new LevelDB(testFolder.getRoot().getAbsolutePath(), options)) { levelDB.put(null, new byte[]{}, writeOptions); } } } }
@Test public void put_null_key_and_null_value() { try(LevelDBOptions options = new LevelDBOptions()) { options.setCreateIfMissing(true); try(LevelDBWriteOptions writeOptions = new LevelDBWriteOptions()) { try (LevelDB levelDB = new LevelDB(testFolder.getRoot().getAbsolutePath(), options)) { levelDB.put(null, null, writeOptions); } } } }