Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.x: Zip, CombineLatest, and Amb operators throw when supplied with ObservableSource implementation that doesn't subclass Observable #6753

Closed
mgsholte opened this issue Dec 10, 2019 · 2 comments · Fixed by #6756

Comments

@mgsholte
Copy link

Issue found in version 2.2.15.

The Zip, CombineLatest, and Amb operators of the Observable class each have an overload that accepts an Iterable<ObservableSource> and a Function<Array<Any>, R> where R is a type parameter. The problem is that the elements of the Iterable are copied into an Observable[] internally by the Observer classes implementing the operators. This causes an ArrayStoreException if one supplies any custom ObservableSource implementation that doesn't subclass Observable.

The equivalent functions for the other stream types don't have this restriction. I.e, the Zip implementation in Maybe copies the source values into a MaybeSource[] and avoids this problem.

Example kotlin code which reproduces the issue:

import io.reactivex.Observable
import io.reactivex.ObservableSource

val sourceA = ObservableSource<String> { Observable.just("A").subscribe(it) }
val sourceB = ObservableSource<String> { Observable.just("b", "B").subscribe(it) }

val combined =
    Observable.combineLatest(
       listOf(sourceA, sourceB),
       { (it[0] as String) + (it[1] as String) }
    )

fun main() {
    combined.subscribe(::println)
}

A simple workaround is to wrap any ObservableSource. To fix the above example pass listOf(sourceA, sourceB).map { Observable.wrap(it) } to combineLatest.

@mgsholte mgsholte changed the title a2.x: Zip, CombineLatest, and Amb operators throw when supplied with ObservableSource implementation that doesn't subclass Observable 2.x: Zip, CombineLatest, and Amb operators throw when supplied with ObservableSource implementation that doesn't subclass Observable Dec 10, 2019
@akarnokd
Copy link
Member

Indeed the initial array for those has the wrong type. Would you like to post a PR?

@mgsholte
Copy link
Author

Sure! I can whip up a PR in a bit.

mgsholte pushed a commit to mgsholte/RxJava that referenced this issue Dec 10, 2019
…bservableSource implementation that doesn't subclass Observable ReactiveX#6753
akarnokd pushed a commit that referenced this issue Dec 11, 2019
…bservableSource implementation that doesn't subclass Observable (#6754)

* 2.x: Zip, CombineLatest, and Amb operators throw when supplied with ObservableSource implementation that doesn't subclass Observable #6753

* 2.x: add tests for allowing arbitrary ObservableSource implementations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants