These are chat archives for ReactiveX/RxJava

11th
Sep 2016
Toon Sevrin
@toonsevrin
Sep 11 2016 21:07
I get this error testing rxJava 2.0 Observable#combineLatest(List, Function): https://i.gyazo.com/ff260887011e13636159534550729424.png
Anyone genius in here? :)
Dorus
@Dorus
Sep 11 2016 21:14
@toonsevrin I'm no genius, but do have a random idea. Did you try Observable.combineLatest<String>(...)?
Toon Sevrin
@toonsevrin
Sep 11 2016 21:16
Is that possible in java?
@Dorus don't think you can do that with methods :P
Dorus
@Dorus
Sep 11 2016 21:20
Yeah i put it in eclipse quickly and it complains about that strings parameter.
Toon Sevrin
@toonsevrin
Sep 11 2016 21:21
Interesting: Intellij says "strings" is of type String[]
2.0.0-RC2?
Dorus
@Dorus
Sep 11 2016 21:23

I followed it trough the source and its calling

 Object[] array = (Object[])q.poll();
...
v = combiner.call(array);

And indeed eclipse complains strings is of type Object

Ok, it's an Object array actually.
So the typing is lost.
That works for me as well
Dorus
@Dorus
Sep 11 2016 21:26
What i did was
        Observable<String> obs = Observable.combineLatest(observableList, (strings) ->  {
            String combo = "";
            String[] stringArray = Arrays.copyOf(strings, strings.length, String[].class);
            for(String s : stringArray)
                combo += s;
            return combo;
        });
Toon Sevrin
@toonsevrin
Sep 11 2016 21:26
Exactly :) that works well
Dorus
@Dorus
Sep 11 2016 21:26
yup
Toon Sevrin
@toonsevrin
Sep 11 2016 21:27
Little less performant though :(
Dorus
@Dorus
Sep 11 2016 21:27
So it loses its typing.
Toon Sevrin
@toonsevrin
Sep 11 2016 21:27
Should I create the issue or is this with reason?
Dorus
@Dorus
Sep 11 2016 21:27
Probably because you can combine different kind of objects.
Toon Sevrin
@toonsevrin
Sep 11 2016 21:27
I remember there was a similar issue like this in v1, so it may be with reason.
aah right
Dorus
@Dorus
Sep 11 2016 21:27
I'm running 1.1.5
Toon Sevrin
@toonsevrin
Sep 11 2016 21:28
I think you're right with it accepting different types of objects
let's quickly try :)
Dorus
@Dorus
Sep 11 2016 21:28
Well i wonder if it's possible to get the type from observableList
Toon Sevrin
@toonsevrin
Sep 11 2016 21:28
Wait if you pass different types
you can just pass a list<object>
Dorus
@Dorus
Sep 11 2016 21:29
If it's a List<Observable<String>> you know it'll only get Strings.
Indeed
Toon Sevrin
@toonsevrin
Sep 11 2016 21:29
Yeh exactly
Dorus
@Dorus
Sep 11 2016 21:29
So i wonder why they decided to drop the type
Toon Sevrin
@toonsevrin
Sep 11 2016 21:29
You can make it List<Observable<Object>> to achieve the current behavior
I think there's an old gh issue on this already in 1.0
saying it's fixed in v2
Dorus
@Dorus
Sep 11 2016 21:31
I wonder if the fix would be as easy as changing that line in rx.internal.operators.OnSubscribeCombineLatest.LatestCoordinator<T, R> from Object[] array = (Object[])q.poll(); to T[] array = (T[])q.poll();
And well, then replace Object with T in a few more places.
Toon Sevrin
@toonsevrin
Sep 11 2016 21:37
I could try :P
Or shall I just post the issue?
Dorus
@Dorus
Sep 11 2016 21:37
Depend on how much time you want to invest in it :)
Toon Sevrin
@toonsevrin
Sep 11 2016 21:38
Haha I have never actually made a pull request :(:(
Gonna keep it that way haha
Dorus
@Dorus
Sep 11 2016 21:39
too shy?
Toon Sevrin
@toonsevrin
Sep 11 2016 21:39
hahaha
Well, I don't study anything remotely related to programming
So chances are relatively high what I would do would be wrong
@toonsevrin Well what i saw from random pull requests is that the devs are more than willing to help out with small mistakes.
Toon Sevrin
@toonsevrin
Sep 11 2016 21:42
Cool, for everything a first time. I'll give it a shot tomorrow.
Gonna create the issue tonight to see if there is somehow a reason for it.
Toon Sevrin
@toonsevrin
Sep 11 2016 21:44
Well I'm currently running 2.x
I remember someone saying this was fixed on an issue
Could you try?
Dorus
@Dorus
Sep 11 2016 21:46
Let me try to swap out 1.x for 2.x in my maven
Toon Sevrin
@toonsevrin
Sep 11 2016 21:46
2.0.0-RC2
Dorus
@Dorus
Sep 11 2016 21:49
Mmm indeed it gives that error....
Toon Sevrin
@toonsevrin
Sep 11 2016 21:49
hmm weird
Dorus
@Dorus
Sep 11 2016 21:49
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
    at RxTest.RxTest.CombineLatest$$Lambda$1/1496724653.apply(Unknown Source)
    at io.reactivex.internal.operators.observable.ObservableCombineLatest$LatestCoordinator.drain(ObservableCombineLatest.java:242)
    at io.reactivex.internal.operators.observable.ObservableCombineLatest$LatestCoordinator.combine(ObservableCombineLatest.java:197)
Toon Sevrin
@toonsevrin
Sep 11 2016 21:49
in the repository on github it looks like it cast
when I decompile my local version
it is not...
Toon Sevrin
@toonsevrin
Sep 11 2016 21:55
could it be that the maven is not updated? >:(
Dorus
@Dorus
Sep 11 2016 21:58
Well this is what i get: Function<? super T[], ? extends R> combiner
Toon Sevrin
@toonsevrin
Sep 11 2016 21:59
me as well
Object[] array = (Object[])((Object[])q.poll());
Dorus
@Dorus
Sep 11 2016 22:01

Nope i see

T[] array = (T[])q.poll();

properly

Toon Sevrin
@toonsevrin
Sep 11 2016 22:02
awtch
Dorus
@Dorus
Sep 11 2016 22:02
And the error is thrown on io.reactivex.internal.operators.observable.ObservableCombineLatest$LatestCoordinator.drain(ObservableCombineLatest.java:242) ->
v = combiner.apply(array);`
Toon Sevrin
@toonsevrin
Sep 11 2016 22:02
And still an
issue?
Dorus
@Dorus
Sep 11 2016 22:02
Something is wrong as T doesnt seem to be of type String
The dubugger gives me: array Object[2] (id=37)
Toon Sevrin
@toonsevrin
Sep 11 2016 22:04
that means? :P
Dorus
@Dorus
Sep 11 2016 22:04
That it's already cast to an Object by then.
Toon Sevrin
@toonsevrin
Sep 11 2016 22:04
I see
``` 
nice...
``` 
        final SpscLinkedArrayQueue<Object> q = queue;
``` 
...
Dorus
@Dorus
Sep 11 2016 22:07
woops
Toon Sevrin
@toonsevrin
Sep 11 2016 22:07
Anyhow could that be the casting issue?
Dorus
@Dorus
Sep 11 2016 22:07
Could be. What file is that?
Toon Sevrin
@toonsevrin
Sep 11 2016 22:08
ObservableCombineLatest
l200
Dorus
@Dorus
Sep 11 2016 22:09
oh i found it on l106
Inside the constructor for LatestCoordinator
Actually the offending one is line 83:
final SpscLinkedArrayQueue<Object> queue;
Toon Sevrin
@toonsevrin
Sep 11 2016 22:10
yey
Dorus
@Dorus
Sep 11 2016 22:10
Yup that looks like what you shared too
Toon Sevrin
@toonsevrin
Sep 11 2016 22:11
So it should just replace Object with T?
Dorus
@Dorus
Sep 11 2016 22:11
l204 has another one: final SpscLinkedArrayQueue<Object> q = queue;
Toon Sevrin
@toonsevrin
Sep 11 2016 22:11
Yep that's the one I pointed
Line 200 on github for me
Dorus
@Dorus
Sep 11 2016 22:11
i see, there are multiple.
Toon Sevrin
@toonsevrin
Sep 11 2016 22:12
so you know if this is easily solvable? :P
Dorus
@Dorus
Sep 11 2016 22:12
Yeah try that. I do think the one around l83 is the offending one as my debugger send me there.
Toon Sevrin
@toonsevrin
Sep 11 2016 22:12
All right I'll write it down for tomorrow.
Bed time now :)
thanks @Dorus!
Dorus
@Dorus
Sep 11 2016 22:12
No idea, but if you try and it works, you'll have a yes ;)
@toonsevrin One last thing, looks like the bug is thrown from Rx, not your user code. I cant even make it run in Rx2. So if you dont get to make a PR, just post an issue and the devs can fix it (esp when you point at line numbers, we found them anyway). Also, goodnight :)
Toon Sevrin
@toonsevrin
Sep 11 2016 22:15
All right, will do!
Thanks for the help haha, I'm happy we've found it.
Gn
Dorus
@Dorus
Sep 11 2016 22:18
Stepped trough the code, looks like line 204 just localizes the object from line 83, so both need to be changed. The debugger does show it as queue SpscLinkedArrayQueue<T> (id=154) but the object is assigned to an SpscLinkedArrayQueue<Object> so the typing is lost.