{
  "id": "java/unsupported-operation-exception-immutable-list",
  "signature": "java.lang.UnsupportedOperationException: Immutable list cannot be modified",
  "signature_zh": "java.lang.UnsupportedOperationException：不可变列表无法修改",
  "regex": "java\\.lang\\.UnsupportedOperationException: Immutable list cannot be modified",
  "domain": "java",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "An attempt was made to modify a collection that was created as immutable (e.g., via List.of(), Collections.unmodifiableList(), or Stream.toList()), which does not support add, remove, or set operations.",
  "root_cause_type": "generic",
  "root_cause_zh": "尝试修改通过 List.of()、Collections.unmodifiableList() 或 Stream.toList() 等方法创建的不可变集合，这些集合不支持 add、remove 或 set 操作。",
  "versions": [
    {
      "version": "Java 9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Java 11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Java 17",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Java 21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Catching and ignoring the exception does not fix the logic; the modification is silently skipped, leading to data inconsistency.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Adding @SuppressWarnings does not change the runtime behavior; the exception still occurs.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Using ArrayList constructor on the immutable list creates a mutable copy, but if the code continues to use the original reference, the error persists.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "If modification is needed, create a mutable copy of the immutable list using the ArrayList constructor, then modify the copy.",
      "success_rate": 0.95,
      "how": "If modification is needed, create a mutable copy of the immutable list using the ArrayList constructor, then modify the copy.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use Stream.collect(Collectors.toList()) to create a mutable list instead of Stream.toList() (which returns an immutable list in Java 16+).",
      "success_rate": 0.9,
      "how": "Use Stream.collect(Collectors.toList()) to create a mutable list instead of Stream.toList() (which returns an immutable list in Java 16+).",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the list is returned from a library and you must modify it, wrap it in a new ArrayList immediately after receiving it.",
      "success_rate": 0.9,
      "how": "If the list is returned from a library and you must modify it, wrap it in a new ArrayList immediately after receiving it.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "If modification is needed, create a mutable copy of the immutable list using the ArrayList constructor, then modify the copy.",
    "Use Stream.collect(Collectors.toList()) to create a mutable list instead of Stream.toList() (which returns an immutable list in Java 16+).",
    "If the list is returned from a library and you must modify it, wrap it in a new ArrayList immediately after receiving it."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/UnsupportedOperationException.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2024-02-14",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}