{"record":{"id":"219c7092e3044a1f","repo":"ReactiveX/RxJava","slug":"remove","errorCode":null,"errorMessage":"remove","messagePattern":"remove","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/reactivex/rxjava4/internal/operators/flowable/BlockingFlowableIterable.java","lineNumber":184,"sourceCode":"\n        void signalConsumer() {\n            lock.lock();\n            try {\n                condition.signalAll();\n            } finally {\n                lock.unlock();\n            }\n        }\n\n        @Override\n        public void run() {\n            SubscriptionHelper.cancel(this);\n            signalConsumer();\n        }\n\n        @Override // otherwise default method which isn't available in Java 7\n        public void remove() {\n            throw new UnsupportedOperationException(\"remove\");\n        }\n\n        @Override\n        public void dispose() {\n            SubscriptionHelper.cancel(this);\n            signalConsumer(); // Just in case it is currently blocking in hasNext.\n        }\n\n        @Override\n        public boolean isDisposed() {\n            return get() == SubscriptionHelper.CANCELLED;\n        }\n    }\n}\n","sourceCodeStart":166,"sourceCodeEnd":199,"githubUrl":"https://github.com/ReactiveX/RxJava/blob/a8ab5356143f37a8f1dd6d76c79191bec5fa343b/src/main/java/io/reactivex/rxjava4/internal/operators/flowable/BlockingFlowableIterable.java#L166-L199","documentation":"Thrown as UnsupportedOperationException('remove') by the Iterator returned by BlockingFlowableIterable when a caller invokes remove(). The iterator exposes a pull-based blocking view over a push-based flowable; mutation operations are not supported, so remove() always throws. This satisfies the java.util.Iterator contract (remove is optional).","triggerScenarios":"Obtaining an Iterator via blockingIterable()/forEach iteration over a flowable and calling iterator.remove() on it — e.g. inside a loop that was adapted from a mutable List pattern.","commonSituations":"Refactoring code that previously iterated and mutated a List (where remove() worked) to stream over a flowable; passing the iterator to a utility that calls remove() (some filtering/cleaning helpers do); generic collection-handling code that probes remove().","solutions":["Do not call remove() on iterators derived from a flowable; collect into a modifiable collection first if you need to mutate.","If you need filtered elements, apply filter() on the flowable before iterating instead of removing during iteration.","Collect into a new ArrayList and mutate that list: flowable.blockingSubscribe(list::add) or blockingStream().toList().","Audit shared iteration utilities to ensure they do not invoke remove() on the supplied iterator."],"exampleFix":"// before\nIterator<T> it = flowable.blockingIterable().iterator();\nwhile (it.hasNext()) {\n    T t = it.next();\n    if (shouldDrop(t)) it.remove(); // throws\n}\n\n// after\nList<T> kept = new ArrayList<>();\nflowable.filter(t -> !shouldDrop(t)).blockingSubscribe(kept::add);","handlingStrategy":"type-guard","validationCode":"// treat the iterator as read-only by contract; never call remove().\n// If mutation is needed, collect first:\nList<T> list = new ArrayList<>();\nflowable.blockingSubscribe(list::add);\nlist.removeIf(this::shouldDrop);","typeGuard":"// iterators from BlockingFlowableIterable are unmodifiable; route mutation\n// through a collected ArrayList instead of iterator.remove().\nboolean isReadOnly(Iterator<?> it) {\n    return it.getClass().getName().contains(\"BlockingFlowable\");\n}","tryCatchPattern":null,"preventionTips":["Never call remove() on iterators obtained from a flowable's blockingIterable().","Do filtering upstream with filter() rather than removing during iteration.","Audit generic collection utilities for unconditional remove() calls."],"tags":["unsupported-operation","iterator","blocking","flowable","rxjava"],"backgroundTag":null,"analyzedSha":"a8ab5356143f37a8f1dd6d76c79191bec5fa343b","analyzedAt":"2026-08-13T23:25:30.069Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}