Database corrupt on Android

I don’t know why, but this morning I suddenly started getting errors in trying to add attachments to a document in Couchbase Mobile. Strangely, even uninstalling and reinstalling my app did not make it go away.

At the time, I was using 1.1.0 so I decided to upgrade as a first step (to 1.3.1). This now dies trying to upgrade my old database as follows:

10-07 14:07:59.007: E/SuisseGarde(19192): java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: src.length=0 srcPos=0 dst.length=192 dstPos=0 length=-1
10-07 14:07:59.007: E/SuisseGarde(19192): at com.couchbase.lite.store.SQLiteStore.runInTransaction(SQLiteStore.java:721)
10-07 14:07:59.007: E/SuisseGarde(19192): at com.couchbase.lite.Database.runInTransaction(Database.java:570)
10-07 14:07:59.007: E/SuisseGarde(19192): at com.couchbase.lite.DatabaseUpgrade.importData(DatabaseUpgrade.java:111)
10-07 14:07:59.007: E/SuisseGarde(19192): at com.couchbase.lite.Manager.upgradeDatabase(Manager.java:857)
10-07 14:07:59.007: E/SuisseGarde(19192): at com.couchbase.lite.Manager.upgradeOldDatabaseFiles(Manager.java:798)
10-07 14:07:59.007: E/SuisseGarde(19192): at com.couchbase.lite.Manager.(Manager.java:130)

Is there data stored somewhere outside of my application? Can I just delete it to get back to things working? If not, what can I do? Obviously, until I have a Manager instance, I’m very constrained in the API calls I can make.

Thanks

So it turns out that deleting the application from Android using just the Settings/Apps panel does NOT clean up the storage associated with the app (databases, files, etc). I’m not sure if there’s a way to do that from the UI, but from adb you can explicitly uninstall the app and NOT give the -k option (which keeps the files).

Thus

adb uninstall <package>

@gareth Can I ask for more details? Uninstalling an app has always removed the associated data, unless you do something unusual. See, e.g., https://groups.google.com/forum/#!topic/android-developers/hrW8OI_u2T4

That’s the behavior I’ve always seen, going through the Settings/Apps panel. Everything is stored under the apps namespace. That whole subtree just gets deleted when you uninstall. So I’m really puzzled by what you’re seeing.

Thanks,
Hod

I’m not sure I really have any more details about that side of the problem. It may be specific to the device I was trying to use (a Sony Xperia X Performance), or it may be that I was missing a configuration option. But certainly doing it by hand using ADB resolved the problem. Since I wasn’t using a “rooted” device I couldn’t actually go in and check what physically was or was not on the device.

The “root” of the problem was that I was trying to “attach” an input stream to an item in Couchbase, and that input stream was itself throwing a (bizarre) error but the “installAttachmentBodies” method in Couchbase that copied the stream was claiming the error as its own, thus confusing me into thinking that something was going wrong inside the Couchbase code.

Once I’d resolved the upgrade problem and checked out the source, it was obvious that “my” exception was being swallowed at Attachment.java:210 (in 1.3.1).

Sorry I can’t be of more help.