RxJava icon indicating copy to clipboard operation
RxJava copied to clipboard

"java.lang.IllegalArgumentException: n >= 0 required" when unsubscribing

Open danhawkes opened this issue 11 years ago • 5 comments

Saw this exception in crash logs, but haven't been able to reproduce it. Any ideas what the cause is?

java.lang.IllegalArgumentException: n >= 0 required
at rx.internal.operators.OperatorMerge$MergeProducer.request(OperatorMerge.java:128)
at rx.internal.operators.OperatorReplay$ReplaySubscriber.manageRequests(OperatorReplay.java:521)
at rx.internal.operators.OperatorReplay$InnerProducer.unsubscribe(OperatorReplay.java:716)
at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:124)
at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:113)
at rx.Subscriber.unsubscribe(Subscriber.java:98)
at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:124)
at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:113)
at rx.Subscriber.unsubscribe(Subscriber.java:98)

https://github.com/ReactiveX/RxJava/blob/v1.0.14/src/main/java/rx/internal/operators/OperatorMerge.java#L128

danhawkes avatar Aug 20 '15 16:08 danhawkes

Could you post the code (or equivalent) which exhibits this problem? Looks like there is a flatmap followed by a replay.

akarnokd avatar Aug 20 '15 16:08 akarnokd

Found the problem. Fix in #3167.

akarnokd avatar Aug 20 '15 17:08 akarnokd

Awesome, thanks for the speedy fix. As a workaround until there's an update to RX, is it be safe to wrap the unsubscribe call in a catch statement? I'd be discarding the entire source observable at that point also.

danhawkes avatar Aug 21 '15 14:08 danhawkes

The bug can leave the operator in inconsistent state and could stop replaying altogether.

akarnokd avatar Aug 21 '15 14:08 akarnokd

Fixed via #3167

akarnokd avatar Sep 03 '15 07:09 akarnokd