Rxjava: 2.x: GroupedObservable#getKey is annotated as Nullable

Created on 27 Jun 2017  路  7Comments  路  Source: ReactiveX/RxJava

(RxJava 2.1.0)
The GroupedObservable's key that the group was created with is annotated as Nullable (in both the return type and in the constructor parameter).

However, the key is only ever created from the keySelector (in ObservableGroupBy), which is declared as a Function (and hence has @NonNull return type). It should therefore be considered a warning to return a null key for a group.

I propose that RxJava actively verifies that the returned key is non-null and then change the Nullable annotations in GroupedObservable to NonNull correspondingly.

2.x Question

Most helpful comment

Ah, Kotlin. Java completely ignores these annotations and as it seems, Kotlin 1.1.3 brought up this trouble around nullability annotations. I'm starting to lean towards removing all such annotations from the functional types.

5442 is the most recent discussion.

All 7 comments

Actually, the implementation allows null keys because such keys are not part of the sequence.

But as far as I can tell, the only way to produce a null key is to return null from the keySelector function, yes? But said Function interface has its return type annotated as NonNull so it would be a warning to do so. When using Kotlin for example, these kinds of warnings can lead to compilation errors or runtime exceptions, since nullable types are different from non-null types.

I'm guessing the topic regarding annotations on the functional interfaces has been brought up before, is there anywhere I can read more about the plans for this?

Ah, Kotlin. Java completely ignores these annotations and as it seems, Kotlin 1.1.3 brought up this trouble around nullability annotations. I'm starting to lean towards removing all such annotations from the functional types.

5442 is the most recent discussion.

Dddamn this is bad. What if we try to convert all RxJava tests from Java to Kotlin then compile and run them with Kotlin 1.1.3 to see if it creates potential problems?

You could create a Kotlin project and just write up streams with functional parameters to see what doesn't compile. I'd expect a thousand flows though.

Closing via #5449.

Hi Guys, could you please help me for this https://stackoverflow.com/questions/47595813/rxkotlin-groupby-is-not-working? working in rxjava but not kotlin. highly apreciate your help

Was this page helpful?
0 / 5 - 0 ratings

Related issues

philleonard picture philleonard  路  3Comments

ZakTaccardi picture ZakTaccardi  路  3Comments

Jaap-van-Hengstum picture Jaap-van-Hengstum  路  3Comments

dimsuz picture dimsuz  路  4Comments

hoc081098 picture hoc081098  路  3Comments