Null values in documents cause corrupted file data - by design?


documents with items having null values seem to cause the file data to be inaccessible and labeled corrupt.

Steps to reproduce:

  1. Save a document with any null values, i.e.
    Document doc = new Document();
    string s = null;
    doc.Set(someKey, s);

  2. Load this document from the database using some appropriate query, i.e.
    IResultSet rows = someQuery.Run();

Step 2 results in:
LiteCore.LiteCoreException: 'LiteCoreException (23): file data is corrupted’
With the error ocurring here:
Couchbase.Lite.dll!LiteCore.Interop.NativeHandler.Execute(LiteCore.Interop.C4TryLogicDelegate2 block) Unknown
Couchbase.Lite.dll!Couchbase.Lite.Internal.Query.XQuery.Run() Unknown

Is this a bug or expected behavior?

I had the error in Android and UWP using Couchbase.Lite 2.0 .NET, db014 (and at least back to db012). It might happen with other OS as well but I didn’t check.

There is a pretty big debate about what to do with null values…should we store them…should we ignore them, etc. None of them involve an exception though, that’s not good design. LiteCoreException is a pretty good indicator of a cross platform behavior (in this case, an incorrect one). Please file an issue here and I’ll look into it for DB016 (DB015’s deadline is today so it won’t make it into that one unfortunately, unless I somehow fixed it by accident)

P.S Could you share the actual query too?

Well, we have to support null because it’s valid JSON.

This could be a LiteCore bug or it could be the platform code passing invalid data to LiteCore. But we need to see a reproducible case to determine what the problem is.

I think I’ve got one. It only happens when the actual null value is requested in the query (via select result). The same document queried in other ways does not show the problem.

Sorry, I forgot to specify the query.
And yes, any query requesting the actual null value (via select result) will show the error.
I submitted an issue as suggested on github
Good luck in resolving the debate :slightly_smiling_face:

The bug has been fixed in LiteCore now. The fix will be in the next developer build. Thanks for catching this!