Couchbase lite 1.4.1 DB encryption issue

We still use Couchbase lite 1.4.1 for one of our projects and currently we are not able to update it to the new version.
We don’t use a DB encryption now.
If we add encryption - it works if we create a new encrypted DB.
If DB was already created without encryption(which is a usual case if you update an application version) - in according to the docs we open the database without encryption(successfully) and use changeEncryptionKey method with the new encryption key.
Unfortunately it leads to the following error:
W/System.err: com.couchbase.lite.CouchbaseLiteException: java.lang.NullPointerException: Attempt to invoke virtual method ‘’ on a null object reference, Status: 500

Does anyone know how to fix this and what is the problem? Any workaround is appreciated.

The subject line of the post is at odds with what is described in the post.
So to confirm my understanding -
you have UPGRADED an app that was running 1.4 version of database to 2.8
You then rekey the the upgraded database with an encryption key and you are seeing an error

Is the above correct?

Have you confirmed that the database upgrade happened properly? i.e. without rekeying , were you able to access documents from upgraded database ? Can you share an example.

Once you have done so , please share the following

  • Are you on Android or Java?
  • The code snippet that is triggering the error (not just the line that shows the use of changeEncryptionKey. Please send the code snippet that provides relevant context around opening database etc).

Hi, Priya! Thanks for the answer.
Let’s say that we use Couchbase lite v1.4.1 in the Android app, but currently without encryption. We can’t update a Couchbase lite lib version, but we have created a new application version with the encryption enabled with the same Couchbase lite v1.4.1 in according to the documentation Java | Couchbase Docs Archive
So if Android app version with unencrypted DB was used on the device - we already have a local Couchbase DB created. And if we install a new application version with the encryption enabled on the same device - we have to use changeEncryptionKey method to encrypt already created DB. On this step mentioned issue appears.

interface ICouchDbCreator {
    fun init()
    fun createDb(name: String): Database?

class CouchDbCreator(private val context: Context) : ICouchDbCreator {

    private var manager: Manager? = null

    override fun init() {
        try {
            manager = Manager(
        } catch (e: IOException) {

    private fun showLogs(isShow: Boolean) {
        if (!isShow) return

        Manager.enableLogging(Log.TAG, Log.VERBOSE)
        Manager.enableLogging(Log.TAG_SYNC_ASYNC_TASK, Log.VERBOSE)
        Manager.enableLogging(Log.TAG_SYNC, Log.VERBOSE)
        Manager.enableLogging(Log.TAG_QUERY, Log.VERBOSE)
        Manager.enableLogging(Log.TAG_VIEW, Log.VERBOSE)
        Manager.enableLogging(Log.TAG_DATABASE, Log.VERBOSE)
        Manager.enableLogging(Log.TAG_CHANGE_TRACKER, Log.VERBOSE)
        Manager.enableLogging(Log.TAG_REMOTE_REQUEST, Log.VERBOSE)

    override fun createDb(name: String): Database? {
        return try {
            val key = getKey();
            manager?.openDatabase(name, getDatabaseOptions(key))
        } catch (e: CouchbaseLiteException) {
            if (e.cblStatus.code == 401) {
                // Here we understand that we have to change encryption key for the existed DB
                return encryptExistingDb(name)

    // For unencrypted DB
    private var oldpass: String? = null

    private fun encryptExistingDb(name: String): Database? {
        return try {
            // Here we open an existed DB successfully
            val db = manager?.openDatabase(name, getDatabaseOptions(oldpass))
            // Here we receive an issue
        } catch (e: CouchbaseLiteException) {

    private fun getDatabaseOptions(key: String?): DatabaseOptions {
        val options = DatabaseOptions()
        options.isCreate = true
        options.encryptionKey = key
        return options

    private fun getKey(): String {
        // Any key
        return "newEncryptionKey";