{"record":{"id":"8a4708cdfc6913fa","repo":"ReactiveX/RxJava","slug":"read-only-iterator-8a4708","errorCode":null,"errorMessage":"Read only iterator","messagePattern":"Read only iterator","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"src/main/java/io/reactivex/rxjava4/internal/operators/flowable/BlockingFlowableMostRecent.java","lineNumber":115,"sourceCode":"                    if (buf == null) {\n                        buf = value;\n                    }\n                    if (NotificationLite.isComplete(buf)) {\n                        throw new NoSuchElementException();\n                    }\n                    if (NotificationLite.isError(buf)) {\n                        throw ExceptionHelper.wrapOrThrow(NotificationLite.getError(buf));\n                    }\n                    return NotificationLite.getValue(buf);\n                }\n                finally {\n                    buf = null;\n                }\n            }\n\n            @Override\n            public void remove() {\n                throw new UnsupportedOperationException(\"Read only iterator\");\n            }\n        }\n    }\n}\n","sourceCodeStart":97,"sourceCodeEnd":120,"githubUrl":"https://github.com/ReactiveX/RxJava/blob/a8ab5356143f37a8f1dd6d76c79191bec5fa343b/src/main/java/io/reactivex/rxjava4/internal/operators/flowable/BlockingFlowableMostRecent.java#L97-L120","documentation":"Thrown by the Iterator returned from Flowable.blockingMostRecent() when its remove() method is called. Blocking operators expose the live stream as a read-only Iterator over the most-recently-emitted value, so mutation via remove() is forbidden by design and always throws UnsupportedOperationException. The iterator reflects a push-based source, so there is no backing collection to remove from.","triggerScenarios":"Calling Iterator.remove() on the iterator obtained from Flowable.blockingMostRecent(initialValue).next() iteration loop; using a generic utility that defensively invokes remove() on any iterator it consumes; Java for-each is fine, but explicit it.remove() after it.next() triggers it.","commonSituations":"Migrating imperative collection-processing code (that used List.remove() semantics) onto a blocking RxJava iterator; helper libraries that call remove() as part of cleanup; copy-paste of a loop template that included it.remove().","solutions":["Remove the it.remove() call from your loop; blocking RxJava iterators are read-only views and never support removal.","If you need to filter, apply Flowable.filter(...) before blockingMostRecent() instead of mutating the iterator.","If a generic helper mandates remove(), wrap the iterator with your own delegating Iterator whose remove() is a no-op.","Collect results into a separate mutable list rather than trying to mutate the source iterator."],"exampleFix":"// before\nIterator<T> it = flowable.blockingMostRecent(initial).iterator();\nwhile (it.hasNext()) { it.next(); it.remove(); }\n// after\nIterator<T> it = flowable.blockingMostRecent(initial).iterator();\nwhile (it.hasNext()) { T v = it.next(); /* use v, never remove() */ }","handlingStrategy":"validation","validationCode":"// Never call remove() on blocking RxJava iterators.\n// Before your loop, confirm the iterator is read-only by design (no runtime check needed);\n// simply omit it.remove().\nIterator<T> it = flowable.blockingMostRecent(initial).iterator();\nwhile (it.hasNext()) {\n    T v = it.next();\n    // process v; do NOT call it.remove()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat all blocking RxJava iterators as unmodifiable views; never call remove().","Filter upstream with Flowable.filter(...) rather than mutating the iterator.","If a generic helper calls remove(), wrap the iterator in a forwarder with a no-op remove().","Collect results into your own mutable collection instead of mutating the source iterator."],"tags":["rxjava","iterator","unsupported-operation","blocking","flowable"],"backgroundTag":null,"analyzedSha":"a8ab5356143f37a8f1dd6d76c79191bec5fa343b","analyzedAt":"2026-08-13T23:25:30.069Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}