Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.

Commit 2cd0ba3

Browse files
author
hideki
committed
Fixed #784 - Emitting null with the ForestDB engine causes segfault
- Fixes are in java-core and java-forestdb. null key should be ignored. - This commit is to add unit test for it.
1 parent 4221039 commit 2cd0ba3

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/androidTest/java/com/couchbase/lite/ViewsTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3231,4 +3231,38 @@ public void map(Map<String, Object> document, Emitter emitter) {
32313231
Log.e(TAG, "Descending query: rows.getCount() = " + rows.getCount());
32323232
assertEquals(0, rows.getCount());
32333233
}
3234+
3235+
//
3236+
public void testEmitWithNullKey() throws Exception {
3237+
// set up view
3238+
View view = database.getView("vu");
3239+
assertNotNull(view);
3240+
view.setMap(new Mapper() {
3241+
@Override
3242+
public void map(Map<String, Object> document, Emitter emitter) {
3243+
// null key -> ignored
3244+
emitter.emit(null, null);
3245+
}
3246+
}, "1");
3247+
assertNotNull(view.getMap());
3248+
assertEquals(0, view.getCurrentTotalRows());
3249+
3250+
// insert 1 doc
3251+
Map<String, Object> dict = new HashMap<String, Object>();
3252+
dict.put("_id", "11111");
3253+
assertNotNull(putDoc(database, dict));
3254+
3255+
// regular query
3256+
Query query = view.createQuery();
3257+
assertNotNull(query);
3258+
QueryEnumerator e = query.run();
3259+
assertNotNull(e);
3260+
assertEquals(0, e.getCount());
3261+
3262+
// query with null key. it should be ignored. this caused exception previously for sqlite
3263+
query.setKeys(Collections.singletonList(null));
3264+
e = query.run();
3265+
assertNotNull(e);
3266+
assertEquals(0, e.getCount());
3267+
}
32343268
}

0 commit comments

Comments
 (0)