Feature/#4876 nonnull annotations#5051
Conversation
|
Maybe it wasn't well articulated, but based on #5023 I thought we try with just the functional interfaces and come back later if it was not enough.
We rather use our own annotations as most tools allow customizing what annotations to consider. Expect futher comments inline. |
akarnokd
left a comment
There was a problem hiding this comment.
All annotations should be RxJava's own.
| */ | ||
| public Disposable scheduleDirect(Runnable run, long delay, TimeUnit unit) { | ||
| @Nonnull | ||
| public Disposable scheduleDirect(@Nonnull Runnable run, long delay, TimeUnit unit) { |
There was a problem hiding this comment.
TimeUnits should also receive our own non-null annotation.
| @SuppressWarnings("rawtypes") | ||
| @Nullable | ||
| static volatile Function<Single, Single> onSingleAssembly; | ||
|
|
There was a problem hiding this comment.
Please don't remove these empty lines.
| */ | ||
| public static void setOnCompletableSubscribe( | ||
| BiFunction<Completable, CompletableObserver, CompletableObserver> onCompletableSubscribe) { | ||
| @Nullable BiFunction<Completable, CompletableObserver, CompletableObserver> onCompletableSubscribe) { |
| @SuppressWarnings("rawtypes") | ||
| public static void setOnObservableSubscribe( | ||
| BiFunction<Observable, Observer, Observer> onObservableSubscribe) { | ||
| @Nullable BiFunction<Observable, Observer, Observer> onObservableSubscribe) { |
| this.mockDisposable = mockDisposable; | ||
| } | ||
|
|
||
| @javax.annotation.Nonnull |
There was a problem hiding this comment.
I don't think it is worth updating the unit tests.
There was a problem hiding this comment.
Idea did it on itself ;-)
If it is ok, I'd just leave it.
| assertNull(RxJavaPlugins.onSingleScheduler(null)); | ||
| //this is not valid, because io.reactivex.functions.Function.apply() does not allow null parameters | ||
| if (false) { | ||
| assertNull(RxJavaPlugins.onComputationScheduler(null)); |
There was a problem hiding this comment.
Instead of "disabling" this, change it to use the thin scheduler below and assertSame instead of null.
There was a problem hiding this comment.
I removed the null checks completely. As you said, below are the assertSame checks. This should be good enough.
|
Thanks for the feedback. I will improve the pull request further. |
| import static java.lang.annotation.ElementType.PARAMETER; | ||
| import static java.lang.annotation.RetentionPolicy.CLASS; | ||
|
|
||
| @Documented |
There was a problem hiding this comment.
Could you add a short javadoc to this and @NonNull while you are at it?
6717518 to
8e8978c
Compare
8e8978c to
ab7e287
Compare
Issue: #4876
Starting to add @nonnull and @nullable annotations.
I decided to add a compileOnly dependency to findbugs:jsr305 artifact.
We could also use "io.reactivex.annotations.NonNull" which already exists. But there is no "io.reactivex.annotations.Nullable" annotation which is at least as important in my experience.
Since these are only annotations, it is no problem when the class files are missing at compile time (JLS 9.6.1.2 Retention).
I have started to add annotations in the Scheduler and RxJavaPlugins.
The test RxJavaPlugins contains some invalid checks using null (lines 1353 and following).
This pull request is work in progress and should be discussed.
Questions so far: