Fixed potential NPE for force inserting deleted revisions
A deleted revision should have an empty body, but if it was null the
attempt to read the body bytes would NPE.
Added a null check for belt and braces.
package com.cloudant.sync.internal.documentstore.callables;
import com.cloudant.sync.documentstore.AttachmentException;
-import com.cloudant.sync.internal.documentstore.DatabaseImpl;
+import com.cloudant.sync.documentstore.DocumentBodyFactory;
import com.cloudant.sync.documentstore.DocumentStoreException;
+import com.cloudant.sync.internal.documentstore.DatabaseImpl;
import com.cloudant.sync.internal.documentstore.InternalDocumentRevision;
import com.cloudant.sync.internal.sqlite.SQLCallable;
import com.cloudant.sync.internal.sqlite.SQLDatabase;
@@ -68,7 +69,9 @@ public class DoForceInsertNewDocumentWithHistoryCallable implements SQLCallable<
callable.parentSequence = parentSequence;
callable.deleted = rev.isDeleted();
callable.current = true;
- callable.data = rev.getBody().asBytes();
+ // If the body is null treat it as empty
+ callable.data = rev.getBody() == null ? DocumentBodyFactory.EMPTY.asBytes() : rev.getBody
+ ().asBytes();
callable.available = true;
long sequence = callable.call(db);
return sequence;
