Couchbase lite 2.0 Android

I am creating documents and creating 4 FTS indexes using cbl2.0.

When running inside a bach
------------------------------------Code -----------------------------------------------
db.inBatch(() -> {
for (Map map : mapList) {
createDoc(doc, db);
}
});

I am getting following Exception
----------------------------Within transaction--------------------------------------
07-05 10:59:43.667 6191-6514/com.diro.test.cbl E/Database: inBatch() beginTransaction()
07-05 10:59:43.914 6191-6514/com.diro.test.cbl E/Database: inBatch() endTransaction()
07-05 10:59:43.967 6191-6514/com.diro.test.cbl E/Database: inBatch() beginTransaction()
07-05 10:59:44.197 6191-6514/com.diro.test.cbl E/LoadContactsActivity: Exception while creating CxDocs
CouchbaseLiteException{domain=1, code=19}
at com.couchbase.lite.internal.bridge.LiteCoreBridge.convertException(LiteCoreBridge.java:21)
at com.couchbase.lite.Document.save(Document.java:460)
at com.couchbase.lite.Document.save(Document.java:363)
at com.couchbase.lite.Database.save(Database.java:192)
at com.diro.test.cbl.LoadContactsActivity.createCx(LoadContactsActivity.java:106)
at com.diro.test.cbl.LoadContactsActivity.lambda$-com_diro_test_cbl_LoadContactsActivity_lambda$7(LoadContactsActivity.java:93)
at com.diro.test.cbl.-$Lambda$8.$m$0(Unknown Source)
at com.diro.test.cbl.-$Lambda$8.run(Unknown Source)
at com.couchbase.lite.Database.inBatch(Database.java:240)
at com.diro.test.cbl.LoadContactsActivity.createDocuments(LoadContactsActivity.java:91)
at com.diro.test.cbl.LoadContactsActivity.lambda$-com_diro_test_cbl_LoadContactsActivity_lambda$3(LoadContactsActivity.java:58)
at com.diro.test.cbl.-$Lambda$7.$m$0(Unknown Source)
at com.diro.test.cbl.-$Lambda$7.apply(Unknown Source)
at io.reactivex.internal.operators.flowable.FlowableMap$MapSubscriber.onNext(FlowableMap.java:64)
at io.reactivex.internal.operators.flowable.FlowableBuffer$PublisherBufferExactSubscriber.onNext(FlowableBuffer.java:126)
at io.reactivex.internal.operators.flowable.FlowableDoOnEach$DoOnEachSubscriber.onNext(FlowableDoOnEach.java:91)
at io.reactivex.internal.operators.flowable.FlowableFilter$FilterSubscriber.tryOnNext(FlowableFilter.java:74)
at io.reactivex.internal.operators.flowable.FlowableFilter$FilterSubscriber.onNext(FlowableFilter.java:52)
at io.reactivex.internal.operators.flowable.FlowableCreate$BufferAsyncEmitter.drain(FlowableCreate.java:521)
at io.reactivex.internal.operators.flowable.FlowableCreate$BufferAsyncEmitter.onNext(FlowableCreate.java:445)
at com.diro.test.cbl.contacts.platform.ContactManager.lambda$-com_diro_test_cbl_contacts_platform_ContactManager_lambda$1(ContactManager.java:610)
at com.diro.test.cbl.contacts.platform.-$Lambda$9.$m$0(Unknown Source)
at com.diro.test.cbl.contacts.platform.-$Lambda$9.subscribe(Unknown Source)
at io.reactivex.internal.operators.flowable.FlowableCreate.subscribeActual(FlowableCreate.java:72)
at io.reactivex.Flowable.subscribe(Flowable.java:12986)
at io.reactivex.internal.operators.flowable.FlowableFilter.subscribeActual(FlowableFilter.java:37)
at io.reactivex.Flowable.subscribe(Flowable.java:12986)
at io.reactivex.internal.operators.flowable.FlowableDoOnEach.subscribeActual(FlowableDoOnEach.java:49)
at io.reactivex.Flowable.subscribe(Flowable.java:12986)
at io.reactivex.internal.operators.flowable.FlowableBuffer.subscribeActual(FlowableBuffer.java:47)
at io.reactivex.Flowable.subscribe(Flowable.java:12986)
at io.reactivex.internal.operators.flowable.FlowableMap.subscribeActual(FlowableMap.java:38)
at io.reactivex.Flowable.subscribe(Flowable.java:12986)
at io.reactivex.internal.operators.flowable.FlowableObserveOn.subscribeActual(FlowableObserveOn.java:56)
at io.reactivex.Flowable.subscribe(Flowable.java:12986)
at io.reactivex.Flowable.subscribe(Flowable.java:12932)
at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.run(FlowableSubscribeOn.java:82)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:154)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: com.couchbase.litecore.LiteCoreException: disk I/O error
at com.couchbase.litecore.Database.put1(Native Method)
at com.co
07-05 10:59:44.298 6191-6191/com.diro.test.cbl E/LoadContactsActivity: Error while loading contacts
CouchbaseLiteException{domain=4, code=1}
at com.couchbase.lite.internal.bridge.LiteCoreBridge.convertException(LiteCoreBridge.java:21)
at com.couchbase.lite.Database.inBatch(Database.java:254)
at com.diro.test.cbl.LoadContactsActivity.createDocuments(LoadContactsActivity.java:91)
at com.diro.test.cbl.LoadContactsActivity.lambda$-com_diro_test_cbl_LoadContactsActivity_lambda$3(LoadContactsActivity.java:58)
at com.diro.test.cbl.-$Lambda$7.$m$0(Unknown Source)
at com.diro.test.cbl.-$Lambda$7.apply(Unknown Source)
at io.reactivex.internal.operators.flowable.FlowableMap$MapSubscriber.onNext(FlowableMap.java:64)
at io.reactivex.internal.operators.flowable.FlowableBuffer$PublisherBufferExactSubscriber.onNext(FlowableBuffer.java:126)
at io.reactivex.internal.operators.flowable.FlowableDoOnEach$DoOnEachSubscriber.onNext(FlowableDoOnEach.java:91)
at io.reactivex.internal.operators.flowable.FlowableFilter$FilterSubscriber.tryOnNext(FlowableFilter.java:74)
at io.reactivex.internal.operators.flowable.FlowableFilter$FilterSubscriber.onNext(FlowableFilter.java:52)
at io.reactivex.internal.operators.flowable.FlowableCreate$BufferAsyncEmitter.drain(FlowableCreate.java:521)
at io.reactivex.internal.operators.flowable.FlowableCreate$BufferAsyncEmitter.onNext(FlowableCreate.java:445)
at com.diro.test.cbl.contacts.platform.ContactManager.lambda$-com_diro_test_cbl_contacts_platform_ContactManager_lambda$1(ContactManager.java:610)
at com.diro.test.cbl.contacts.platform.-$Lambda$9.$m$0(Unknown Source)
at com.diro.test.cbl.contacts.platform.-$Lambda$9.subscribe(Unknown Source)
at io.reactivex.internal.operators.flowable.FlowableCreate.subscribeActual(FlowableCreate.java:72)
at io.reactivex.Flowable.subscribe(Flowable.java:12986)
at io.reactivex.internal.operators.flowable.FlowableFilter.subscribeActual(FlowableFilter.java:37)
at io.reactivex.Flowable.subscribe(Flowable.java:12986)
at io.reactivex.internal.operators.flowable.FlowableDoOnEach.subscribeActual(FlowableDoOnEach.java:49)
at io.reactivex.Flowable.subscribe(Flowable.java:12986)
at io.reactivex.internal.operators.flowable.FlowableBuffer.subscribeActual(FlowableBuffer.java:47)
at io.reactivex.Flowable.subscribe(Flowable.java:12986)
at io.reactivex.internal.operators.flowable.FlowableMap.subscribeActual(FlowableMap.java:38)
at io.reactivex.Flowable.subscribe(Flowable.java:12986)
at io.reactivex.internal.operators.flowable.FlowableObserveOn.subscribeActual(FlowableObserveOn.java:56)
at io.reactivex.Flowable.subscribe(Flowable.java:12986)
at io.reactivex.Flowable.subscribe(Flowable.java:12932)
at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.run(FlowableSubscribeOn.java:82)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:154)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: com.couchbase.litecore.LiteCoreException: cannot commit - no transaction is active
at com.couchbase.litecore.Database.endTransaction(Native Method)
at com.couchbase.lite.Database.inBatch(Database.java:248)
at com.diro.test.cbl.LoadContactsActivity.createDocuments(LoadContactsActivity.java:91)
at com.diro.test.cbl.LoadContactsActivity.lambda$-com_diro_test_cbl_LoadContactsActivity_lambda$3(LoadContactsActivity.java:58)
at com.diro.test.cbl.-$Lambda$7.$m$0(Unknown Source)
at com.diro.test.cbl.-$Lambda$7.apply(Unknown Source)
at io.reactivex.internal.operators.flowable.FlowableMap$MapSubscriber.onNext(FlowableMap.java:64)
at io.reactivex.internal.operators.flowable.FlowableBuffer$PublisherBufferExactSubscriber.onNext(FlowableBuffer.java:126)
at io.reactivex.internal.operators.flowable.FlowableDoOnEach$DoOnEachSubscriber.onNext(FlowableDoOnEach.java:91)
at io.reactivex.internal.operators.flowable.FlowableFilter$FilterSubscriber.tryOnNext(FlowableFilter.java:74)
at io.reactivex.internal.operators.flowable.FlowableFilter$FilterSubscriber.onNext(FlowableFilter.java:52)
at io.reactivex.internal.operators.flowable.FlowableCreate$BufferAsyncEmitter.drain(FlowableCreate.java:521)
at io.reactivex.internal.operators.flowable.FlowableCreate$BufferAsyncEmitter.onNext(FlowableCreate.java:445)
at com.diro.test.cbl.contacts.platform.ContactManager.lambda$-com_diro_test_cbl_contacts_platform_ContactManager_lambda$1(ContactManager.java:610)
at com.diro.test.cbl.contacts.platform.-$Lambda$9.$m$0(Unknown Source)
at com.diro.test.cbl.contacts.platform.-$Lambda$9.subscribe(Unknown Source)
at io.reactivex.internal.operators.flowable.FlowableCreate.subscribeActual(FlowableCreate.java:72)
at io.reactivex.Flowable.subscribe(Flowable.java:12986)
at io.reactivex.internal.operators.flowable.FlowableFilter.subscribeActual(FlowableFilter.java:37)
at io.reactivex.Flowable.subscribe(Flowable.java:12986)
at io.reactivex.internal.operators.flowable.FlowableDoOnEach.subscribeActual(FlowableDoOnEach.java:49)
at io.reactivex.Flowable.subscribe(Flowable.java:12986)
at io.reactivex.internal.operators.flowable.FlowableBuffer.subscribeActual(FlowableBuffer.java:47)
at io.reactivex.Flowable.subscribe(Flowable.java:12986)
at io.reactivex.internal.operators.flowable.FlowableMap.subscribeActual(FlowableMap.java:38)
at io.reactivex.Flowable.subscribe(Flowable.java:12986)
at io.reactivex.internal.operators.flowable.FlowableObserveOn.subscribeActual(FlowableObserveOn.java:56)
at io.reactivex.Flowable.subscribe(Flowable.java:12986)
at io.reactivex.Flowable.subscribe(Flowable.java:12932)
at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.run(FlowableSubscribeOn.java:82)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:154)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)


-----------------------Without batching--------------------------------------
07-05 10:55:30.542 835-1232/com.diro.test.cbl E/LoadContactsActivity: Exception while creating CxDocs
java.lang.NullPointerException: Attempt to invoke virtual method ‘void com.couchbase.litecore.Document.free()’ on a null object reference
at com.couchbase.lite.Document.save(Document.java:485)
at com.couchbase.lite.Document.save(Document.java:363)
at com.couchbase.lite.Database.save(Database.java:192)

Thanks for reporting this; it looks like a bug in the Android/Java code:

Caused by: com.couchbase.litecore.LiteCoreException: cannot commit - no transaction is active
at com.couchbase.litecore.Database.endTransaction(Native Method)
at com.couchbase.lite.Database.inBatch(Database.java:248)

@hideki, any ideas?

-----------------------Without batching--------------------------------------
07-05 10:55:30.542 835-1232/com.diro.test.cbl E/LoadContactsActivity: Exception while creating CxDocs
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.couchbase.litecore.Document.free()' on a null object reference
at com.couchbase.lite.Document.save(Document.java:485)
at com.couchbase.lite.Document.save(Document.java:363)
at com.couchbase.lite.Database.save(Database.java:192)

This one looks like it’s a bug in your code — you probably passed a null Document to Database.save().

Hi @neeraj.kumar,
Thank you for experimenting CBL 2.0, and also reporting this problem.

with inBatch()

The code 19 means int kC4ErrorIOError = 19; // File I/O error
However, I am not sure how I/O error was caused.
Can you write unit test that can reproduce this problem, or write small sample codes to reproduce this?

without inBatch()

NullPointerException is caused by CBL Android code that is triggered by failing to save the document. We will track NPE issue with the ticket: https://github.com/couchbase/couchbase-lite-android/issues/1243 .
We’d like to know what is root cause of this problem. unit test code or sample code will help us to investigate.

Thanks a lot!

The problem was with in the indexes
I was creating two indexes for some reason, suppose For a contact one index of Phone number(9999999999) and one for last seven digits(9999999) of a phone number then I was getting this error.

I removed index for last seven digits and problem was solved.

@neeraj.kumar Thanks for your response.

That error still shouldn’t be possible. Could you show the code you were using to create the indexes?

 public void createIndex() {
        try {
              db.createIndex(getIndex(CX_SEARCH), IndexType.FullText, new IndexOptions(null, false));
              db.createIndex(getIndex(CX_PHONE), IndexType.FullText, new IndexOptions(null, false));
              db.createIndex(getIndex(CX_PHONE_LASTSEVEN), IndexType.FullText, new IndexOptions(null, false));
        } catch (CouchbaseLiteException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        }
    }

private List<Expression> getIndex(String key) {
    ArrayList<Expression> indexes = new ArrayList<>();
    indexes.add(Expression.property(key));
    return indexes;
}

Json
{
“displayname”:“Jens”
“phone” : [{“home” : “9999999999”},{“work”:“8888888888”}]
“search”:“Jens 9999999999 8888888888” //FTS in display name + phone numbers
"phone":“9999999999 8888888888” //FTS in phone numbers(I know not required as above FTS can do that)
“lastseven”:“9999999 8888888” //FTS in last seven
}

If I create only one index for search then things are working like charm. But if create phone index and lastseven index too then I get above mentioned error. and commenting these two indexes then things back to normal