{"record":{"id":"6d0d45c8617da3a8","repo":"elastic/elasticsearch","slug":"classname-does-not-support-removeall","errorCode":null,"errorMessage":"${className} does not support removeAll()","messagePattern":"(.+?) does not support removeAll\\(\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"build-tools/src/main/java/org/elasticsearch/gradle/LazyPropertyList.java","lineNumber":103,"sourceCode":"\n    @Override\n    public boolean addAll(Collection<? extends T> c) {\n        c.forEach(this::add);\n        return true;\n    }\n\n    @Override\n    public boolean addAll(int index, Collection<? extends T> c) {\n        int i = index;\n        for (T item : c) {\n            this.add(i++, item);\n        }\n        return true;\n    }\n\n    @Override\n    public boolean removeAll(Collection<?> c) {\n        throw new UnsupportedOperationException(this.getClass().getName() + \" does not support removeAll()\");\n    }\n\n    @Override\n    public boolean retainAll(Collection<?> c) {\n        throw new UnsupportedOperationException(this.getClass().getName() + \" does not support retainAll()\");\n    }\n\n    @Override\n    public void clear() {\n        delegate.clear();\n    }\n\n    @Override\n    public T get(int index) {\n        PropertyListEntry<T> entry = delegate.get(index);\n        validate(entry);\n        return entry.getValue();\n    }","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools/src/main/java/org/elasticsearch/gradle/LazyPropertyList.java#L85-L121","documentation":"LazyPropertyList overrides List.removeAll(Collection) to throw UnsupportedOperationException for the same reason as remove(): bulk removal would force eager evaluation of all deferred suppliers and lose PropertyNormalization metadata. The class is an append/replace-oriented lazy view, not a fully mutable list.","triggerScenarios":"Calling .removeAll(Collection) on a LazyPropertyList. Encountered when generic collection algorithms (filtering, differencing) operate on the list, or when code attempts to diff two lists and subtract.","commonSituations":"Refactoring config-building code that did list.removeAll(obsoleteEntries) onto a LazyPropertyList; Gradle plugins that prune entries conditionally; copy-paste from ArrayList-based code.","solutions":["Filter into a new list and rebuild: clear() then addAll() the kept entries.","Hoist the removeAll logic to operate on a plain List<T> before populating the LazyPropertyList.","If using Gradle's ListProperty, prefer filtering at the provider level rather than mutating the lazy list."],"exampleFix":"// before\nlazyList.removeAll(staleEntries); // UnsupportedOperationException\n// after\nList<T> kept = lazyList.stream().filter(Predicate.not(staleEntries::contains)).toList();\nlazyList.clear();\nkept.forEach(lazyList::add);","handlingStrategy":"validation","validationCode":"if (list instanceof LazyPropertyList) {\n    throw new IllegalStateException(\"removeAll() not supported on LazyPropertyList\");\n}","typeGuard":"static boolean isLazyPropertyList(List<?> l) { return l instanceof LazyPropertyList; }","tryCatchPattern":"try { list.removeAll(c); } catch (UnsupportedOperationException e) { /* rebuild: filter and clear+addAll */ }","preventionTips":["Filter into a new list and rebuild (clear + addAll) rather than removeAll.","Keep plain ArrayList instances for any collection that needs bulk removal.","Audit generic collection helpers that may invoke the full List contract."],"tags":["gradle","build-tools","lazy-collection","unsupported-operation"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}