{"record":{"id":"f1df02b383abfc1f","repo":"projectlombok/lombok","slug":"list-is-immutable","errorCode":null,"errorMessage":"List is immutable","messagePattern":"List is immutable","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/utils/lombok/core/LombokImmutableList.java","lineNumber":177,"sourceCode":"\t\tfor (Object e : content) if (in.equals(e)) return true;\n\t\treturn false;\n\t}\n\t\n\tpublic Iterator<T> iterator() {\n\t\treturn new Iterator<T>() {\n\t\t\tprivate int idx = 0;\n\t\t\t@Override public boolean hasNext() {\n\t\t\t\treturn idx < content.length;\n\t\t\t}\n\t\t\t\n\t\t\t@SuppressWarnings(\"unchecked\")\n\t\t\t@Override public T next() {\n\t\t\t\tif (idx < content.length) return (T) content[idx++];\n\t\t\t\tthrow new NoSuchElementException();\n\t\t\t}\n\t\t\t\n\t\t\t@Override public void remove() {\n\t\t\t\tthrow new UnsupportedOperationException(\"List is immutable\");\n\t\t\t}\n\t\t};\n\t}\n\t\n\t@Override public String toString() {\n\t\treturn Arrays.toString(content);\n\t}\n\t\n\t@Override public boolean equals(Object obj) {\n\t\tif (!(obj instanceof LombokImmutableList)) return false;\n\t\tif (obj == this) return true;\n\t\treturn Arrays.equals(content, ((LombokImmutableList<?>) obj).content);\n\t}\n\t\n\t@Override public int hashCode() {\n\t\treturn Arrays.hashCode(content);\n\t}\n}","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/projectlombok/lombok/blob/6d6a3e9fec0a9555702561fbeb8eac836575116e/src/utils/lombok/core/LombokImmutableList.java#L159-L195","documentation":"LombokImmutableList is a persistent, immutable list; its iterator's remove() (and mutating operations generally) always throws UnsupportedOperationException(\"List is immutable\"). The class exists so cached/shared lists can never be modified in place.","triggerScenarios":"Calling iterator().remove(), or any add/set/remove mutating method, on a LombokImmutableList instance — e.g. iterating a list obtained from lombok internals and trying to remove elements, or passing it to code that mutates collections in place.","commonSituations":"Framework code (e.g. processors or serializers) that defensively removes items from a passed-in List; cleanup loops calling it.remove(); tests assuming java.util.ArrayList semantics.","solutions":["Copy into a mutable list before mutating: new ArrayList<>(immutableList), then add/remove on the copy.","Do not call remove() on its iterator; filter instead (build a new list of wanted elements).","If you control the producer, return/maintain a mutable List when in-place mutation is required.","In cleanup-style loops, use Collection.removeIf on a mutable copy."],"exampleFix":"// before\nfor (Iterator<String> it = list.iterator(); it.hasNext(); ) {\n    if (it.next().isEmpty()) it.remove(); // UnsupportedOperationException\n}\n// after\nList<String> mutable = new ArrayList<>(list);\nmutable.removeIf(String::isEmpty);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// treat any List as possibly immutable; wrap before mutating\nstatic <T> List<T> mutableCopy(List<T> l) {\n    return l instanceof java.util.ArrayList<T> ? l : new ArrayList<>(l);\n}","tryCatchPattern":"try {\n    it.remove();\n} catch (UnsupportedOperationException e) {\n    // list is immutable: fall back to a mutable copy\n    list = new ArrayList<>(list);\n}","preventionTips":["Never mutate LombokImmutableList in place; always copy with new ArrayList<>(...) first.","Avoid passing immutable lists to third-party code that mutates collections.","Replace iterator-based removal with removeIf on a mutable copy.","Assume lombok-internal lists are immutable and read-only."],"tags":["immutability","collections","java","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"6d6a3e9fec0a9555702561fbeb8eac836575116e","analyzedAt":"2026-09-07T23:18:01.841Z","contentChangedAt":"2026-09-07T23:18:01.841Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}