{"record":{"id":"1c9d965ea0196b9c","repo":"elastic/elasticsearch","slug":"classname-does-not-support-remove","errorCode":null,"errorMessage":"${className} does not support remove()","messagePattern":"(.+?) does not support remove\\(\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"build-tools/src/main/java/org/elasticsearch/gradle/LazyPropertyList.java","lineNumber":78,"sourceCode":"        return delegate.stream().peek(this::validate).map(PropertyListEntry::getValue).toList().toArray(a);\n    }\n\n    @Override\n    public boolean add(T t) {\n        return delegate.add(new PropertyListEntry<>(() -> t, PropertyNormalization.DEFAULT));\n    }\n\n    public boolean add(Supplier<T> supplier) {\n        return delegate.add(new PropertyListEntry<>(supplier, PropertyNormalization.DEFAULT));\n    }\n\n    public boolean add(Supplier<T> supplier, PropertyNormalization normalization) {\n        return delegate.add(new PropertyListEntry<>(supplier, normalization));\n    }\n\n    @Override\n    public boolean remove(Object o) {\n        throw new UnsupportedOperationException(this.getClass().getName() + \" does not support remove()\");\n    }\n\n    @Override\n    public boolean containsAll(Collection<?> c) {\n        return delegate.stream().map(PropertyListEntry::getValue).collect(Collectors.toSet()).containsAll(c);\n    }\n\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);","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools/src/main/java/org/elasticsearch/gradle/LazyPropertyList.java#L60-L96","documentation":"LazyPropertyList deliberately overrides List.remove(Object) to throw UnsupportedOperationException. The list stores deferred Supplier entries with per-entry PropertyNormalization metadata; removing by resolved value would force eager evaluation of every lazy supplier and discard normalization info, so the operation is intentionally unsupported rather than silently lossy. Use clear() to reset or remove(int) is NOT supported either via this path.","triggerScenarios":"Calling .remove(Object) on any LazyPropertyList instance. This commonly happens when passing a LazyPropertyList to generic List-manipulation utilities, collection algorithms, or third-party code that invokes the full List contract.","commonSituations":"Using libraries that call remove() defensively (e.g., list.removeAll(Collections.singletonList(x))); refactoring a plain ArrayList to LazyPropertyList and discovering mutation methods are gone; Gradle plugin code that mutates lists passed across task boundaries.","solutions":["Rebuild the list from scratch instead of removing an element: collect desired entries and clear()+addAll().","If you control the call site, switch to index-based mutation via set(int, T) or add(int, T).","Avoid passing LazyPropertyList to generic collection helpers; copy to a plain ArrayList first if mutation is required."],"exampleFix":"// before\nlazyList.remove(unwanted); // UnsupportedOperationException\n// after\nList<T> kept = new ArrayList<>(lazyList);\nkept.remove(unwanted);\nlazyList.clear();\nkept.forEach(lazyList::add);","handlingStrategy":"validation","validationCode":"// Before mutating, check the operation is supported\nif (list instanceof LazyPropertyList) {\n    throw new IllegalStateException(\"remove() not supported on LazyPropertyList; rebuild the list instead\");\n}","typeGuard":"static boolean isLazyPropertyList(List<?> l) { return l instanceof LazyPropertyList; }","tryCatchPattern":"try { list.remove(o); } catch (UnsupportedOperationException e) { /* rebuild list from scratch */ }","preventionTips":["Treat LazyPropertyList as append/replace-only; do not call remove, removeAll, or retainAll.","Avoid passing LazyPropertyList to generic collection utilities; copy to ArrayList first if mutation is needed.","Document at construction sites that the list is not fully mutable."],"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"}