{"action":"created","issue":{"url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/1009","repository_url":"https://api.github.com/repos/couchbase/couchbase-lite-android","labels_url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/1009/labels{/name}","comments_url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/1009/comments","events_url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/1009/events","html_url":"https://github.com/couchbase/couchbase-lite-android/issues/1009","id":180061110,"number":1009,"title":"attempt to re-open an already-closed object (1.3.1)","user":{"login":"trramsiq","id":13846439,"avatar_url":"https://avatars.githubusercontent.com/u/13846439?v=3","gravatar_id":"","url":"https://api.github.com/users/trramsiq","html_url":"https://github.com/trramsiq","followers_url":"https://api.github.com/users/trramsiq/followers","following_url":"https://api.github.com/users/trramsiq/following{/other_user}","gists_url":"https://api.github.com/users/trramsiq/gists{/gist_id}","starred_url":"https://api.github.com/users/trramsiq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trramsiq/subscriptions","organizations_url":"https://api.github.com/users/trramsiq/orgs","repos_url":"https://api.github.com/users/trramsiq/repos","events_url":"https://api.github.com/users/trramsiq/events{/privacy}","received_events_url":"https://api.github.com/users/trramsiq/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/couchbase/couchbase-lite-android/labels/needsmoreinfo","name":"needsmoreinfo","color":"5319e7"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-29T14:14:26Z","updated_at":"2016-09-29T17:08:17Z","closed_at":null,"body":"I'm getting an error once in a while in an AsyncTask:\r\n\r\n`compile 'com.couchbase.lite:couchbase-lite-android:1.3.1'`\r\n\r\n```\r\nFatal Exception: java.lang.RuntimeException: An error occured while executing doInBackground()\r\n       at android.os.AsyncTask$3.done(AsyncTask.java:300)\r\n       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)\r\n       at java.util.concurrent.FutureTask.setException(FutureTask.java:222)\r\n       at java.util.concurrent.FutureTask.run(FutureTask.java:242)\r\n       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)\r\n       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)\r\n       at java.lang.Thread.run(Thread.java:841)\r\nCaused by java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/data/com.app/files/user.cblite2/db.sqlite3\r\n       at com.couchbase.lite.internal.database.sqlite.SQLiteClosable.acquireReference(SourceFile:60)\r\n       at com.couchbase.lite.internal.database.sqlite.SQLiteDatabase.beginTransaction(SourceFile:497)\r\n       at com.couchbase.lite.internal.database.sqlite.SQLiteDatabase.beginTransaction(SourceFile:410)\r\n       at com.couchbase.lite.storage.SQLiteStorageEngineBase.beginTransaction(SourceFile:150)\r\n       at com.couchbase.lite.store.SQLiteStore.beginTransaction(SourceFile:2309)\r\n       at com.couchbase.lite.store.SQLiteStore.add(SourceFile:1412)\r\n       at com.couchbase.lite.Database.put(SourceFile:1844)\r\n       at com.couchbase.lite.Database.putRevision(SourceFile:1794)\r\n       at com.couchbase.lite.Database.putRevision(SourceFile:1785)\r\n       at com.couchbase.lite.Document.putProperties(SourceFile:523)\r\n       at com.couchbase.lite.Document.putProperties(SourceFile:350)\r\n       at com.app.DevUtilities.Cache.Cache.store(SourceFile:76)\r\n       at com.app.DevUtilities.Cache.CacheObject.apply(SourceFile:46)\r\n       at com.app.Models.Account.Account.save(SourceFile:155)\r\n       at com.app.Models.Account.Account.setOrUpdateAccount(SourceFile:191)\r\n       at com.app.Models.Account.Account.loadApiAccountIntoDb(SourceFile:301)\r\n       at com.app.Fragments.ActivityStream.Controller.ActivityStreamController$ActivityTask.doInBackground(SourceFile:244)\r\n       at com.app.Fragments.ActivityStream.Controller.ActivityStreamController$ActivityTask.doInBackground(SourceFile:215)\r\n       at android.os.AsyncTask$2.call(AsyncTask.java:288)\r\n       at java.util.concurrent.FutureTask.run(FutureTask.java:237)\r\n       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)\r\n       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)\r\n       at java.lang.Thread.run(Thread.java:841)\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/comments/250529827","html_url":"https://github.com/couchbase/couchbase-lite-android/issues/1009#issuecomment-250529827","issue_url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/1009","id":250529827,"user":{"login":"trramsiq","id":13846439,"avatar_url":"https://avatars.githubusercontent.com/u/13846439?v=3","gravatar_id":"","url":"https://api.github.com/users/trramsiq","html_url":"https://github.com/trramsiq","followers_url":"https://api.github.com/users/trramsiq/followers","following_url":"https://api.github.com/users/trramsiq/following{/other_user}","gists_url":"https://api.github.com/users/trramsiq/gists{/gist_id}","starred_url":"https://api.github.com/users/trramsiq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trramsiq/subscriptions","organizations_url":"https://api.github.com/users/trramsiq/orgs","repos_url":"https://api.github.com/users/trramsiq/repos","events_url":"https://api.github.com/users/trramsiq/events{/privacy}","received_events_url":"https://api.github.com/users/trramsiq/received_events","type":"User","site_admin":false},"created_at":"2016-09-29T17:08:17Z","updated_at":"2016-09-29T17:08:17Z","body":"Hi @hideki,\r\n\r\nThanks for getting back at me!\r\nThe background method is:\r\n```\r\nprotected Void doInBackground(String... urls) {\r\n\r\n            // Collect all accounts in data\r\n            ArrayList<Account> accountsToStore = new ArrayList<>();\r\n            for (Tile tile : response.activity) {\r\n                if (tile.account != null) {\r\n                    accountsToStore.add(tile.account);\r\n                } else if (tile.accounts != null) {\r\n                    accountsToStore.addAll(tile.accounts);\r\n                }\r\n            }\r\n            // Load collected accounts into cache\r\n            Account.loadApiAccountIntoDb(accountsToStore); <----- line 244\r\n\r\n            return null;\r\n        }\r\n```\r\n\r\nThe store methods looks like:\r\n```\r\npublic static void store(String cache, String id, String content) {\r\n\r\n        Document retrievedDocument = null;\r\n        try {\r\n            retrievedDocument = Application.getInstance().getUserDatabaseInstance().getDocument(id);\r\n            Map<String, Object> updatedProperties = new HashMap<String, Object>();\r\n            Map<String, Object> currentProperties = retrievedDocument.getProperties();\r\n            if (currentProperties != null && currentProperties.size() != 0) {\r\n                updatedProperties.putAll(currentProperties);\r\n            }\r\n            updatedProperties.put(\"1\", content);\r\n            retrievedDocument.putProperties(updatedProperties);  <------ line 76\r\n        } catch (CouchbaseLiteException e) {\r\n            e.printStackTrace();\r\n        }\r\n    }\r\n```\r\n\r\nThe application code:\r\n```\r\nManager manager = null;\r\n   Database user_database = null;\r\n\r\n    public Database getUserDatabaseInstance() throws CouchbaseLiteException {\r\n        if (this.user_database == null) {\r\n            try {\r\n                this.user_database = getManagerInstance().getDatabase(Cache.USER_DB);\r\n            } catch (IOException e) {\r\n                e.printStackTrace();\r\n            }\r\n            if (this.user_database == null && this.manager != null){\r\n                File srcDir = new File(manager.getContext().getFilesDir(), Cache.USER_DB +\".cblite2\");\r\n                this.manager.replaceDatabase(Cache.USER_DB, srcDir.getAbsolutePath());\r\n            }\r\n        }\r\n        return user_database;\r\n    }\r\n\r\n    public Manager getManagerInstance() throws IOException {\r\n        if (manager == null) {\r\n            manager = new Manager(new AndroidContext(this), Manager.DEFAULT_OPTIONS);\r\n        }\r\n        return manager;\r\n    }\r\n\r\n```"}}
{"actor":{"display_login":"trramsiq"}}