Couchbase Lite C assertion error when updating already existing property of document

Sometimes when I try to set a key into an FLDict where the key alreaday exists, I get the following assertion:

FAILED PRECONDITION: index<_items.size() not true when calling class fleece::impl::ValueSlot &__cdecl fleece::impl::internal::HeapArray::setting(unsigned int) (at line 129)

I can’t get a stack trace, because I’m calling in from Dart and I have no idea how to do it yet, but here’s a C code that reproduces the same error.

The error seems to happens when:

  1. the key already exists in the dictionary
  2. AND I try to save the document - (ie. if I don’t call CBLDatabase_SaveDocument, I don’t get the error).
  3. AND I haven’t done any “read” operation before hand. This last one is weird, basically if I do FLDict_Get(props, slice("foo")); , or do an FLDump on the properties, or even just read a completely different document beforehand (the first two commented lines in my code) then I don’t get the error at all and the document is updated correctly in the database.

If the key doesn’t already exists none of this happens.

 void DocTest(CBLDatabase *db) {
     // CBLDocument *doc1 = CBLDatabase_GetMutableDocument(db, "testdoc2");
     // doc1->properties().get("foo");
     CBLError *outError = &CBLError{};
     CBLDocument *doc = CBLDatabase_GetMutableDocument(db, "testdoc1");
     MutableDict props = CBLDocument_MutableProperties(doc);
     // FLDict_Get(props, slice("foo"));
     FLSlot sl = FLMutableDict_Set(props, slice("testkey"));
     FLSlot_SetInt(sl, 15);
     CBLDatabase_SaveDocument(db, doc, {kCBLConcurrencyControlLastWriteWins}, outError);

I’m working with a very simple test document here:

“_id”: “testdoc1”,
“foo”: “bar”,
“testkey”: 15

Apart from doing a dummy read, before every write I don’t know how to work around this.
Edit: the dummy read has to be before setting the new value, not before the save.

Can you give us a clue about which product you are using? I’m guessing this is Android… Which version?


Sorry, it’s the coubase-lite-C library.

NP. Which version? (20-chars)

I’m using the latest commit, built on Windows.

I’m using a Dart binding I wrote using ffi, and initially I though it might me something in the Fleece API I missed, but the C code I posted above (the DocTest function) has the same problem.

Perfect. Thanks …

Did you file the issue on the GitHub repo ?

Definitely not, the error happens with a new empty database.

I opened an issue for it here