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: GroupedObservable#getKey is annotated as Nullable #5448

Closed
ajarl opened this issue Jun 27, 2017 · 7 comments
Closed

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

ajarl opened this issue Jun 27, 2017 · 7 comments

Comments

@ajarl
Copy link

ajarl commented Jun 27, 2017

(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.

@akarnokd
Copy link
Member

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

@ajarl
Copy link
Author

ajarl commented Jun 27, 2017

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?

@akarnokd
Copy link
Member

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.

@artem-zinnatullin
Copy link
Contributor

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?

@akarnokd
Copy link
Member

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.

@akarnokd
Copy link
Member

akarnokd commented Jul 5, 2017

Closing via #5449.

@akarnokd akarnokd closed this as completed Jul 5, 2017
@rezakhmf
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants