{
  "id": "android/illegalstateexception-room-database-close",
  "signature": "IllegalStateException: Room database is already closed and cannot be used",
  "signature_zh": "IllegalStateException：Room 数据库已关闭且无法使用",
  "regex": "IllegalStateException: Room database is already closed and cannot be used",
  "domain": "android",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A Room database instance was closed (e.g., via close() or lifecycle destruction) but code tries to perform database operations afterwards.",
  "root_cause_type": "generic",
  "root_cause_zh": "Room 数据库实例已关闭（例如通过 close() 或生命周期销毁），但后续代码尝试执行数据库操作。",
  "versions": [
    {
      "version": "Room 2.5.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Room 2.6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Room 2.6.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Android 13",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Android 14",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Reopening the database manually with `Room.databaseBuilder(context, AppDatabase.class, \"db\").build()` creates a new instance but may cause memory leaks if old references persist.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Using `try-catch` to ignore the exception hides the underlying concurrency issue and may lead to data corruption.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Calling `database.close()` in Application.onCreate() thinking it's safe, but it actually closes the singleton instance prematurely.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use a singleton pattern for the database instance and ensure it is never closed manually; let the Application lifecycle manage it. Example: `AppDatabase.getInstance(context)` always returns the same instance without close().",
      "success_rate": 0.9,
      "how": "Use a singleton pattern for the database instance and ensure it is never closed manually; let the Application lifecycle manage it. Example: `AppDatabase.getInstance(context)` always returns the same instance without close().",
      "condition": "",
      "sources": []
    },
    {
      "action": "Add a null check before database operations: `if (database.isOpen()) { database.someDao().query(); }` to avoid accessing closed database.",
      "success_rate": 0.85,
      "how": "Add a null check before database operations: `if (database.isOpen()) { database.someDao().query(); }` to avoid accessing closed database.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Use a singleton pattern for the database instance and ensure it is never closed manually; let the Application lifecycle manage it. Example: `AppDatabase.getInstance(context)` always returns the same instance without close().",
    "Add a null check before database operations: `if (database.isOpen()) { database.someDao().query(); }` to avoid accessing closed database."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://developer.android.com/training/data-storage/room",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.88,
  "resolvable": "true",
  "first_seen": "2023-03-22",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}