-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Feature/#4876 nonnull annotations #5051
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All annotations should be RxJava's own.
@@ -122,7 +126,8 @@ public Disposable scheduleDirect(Runnable run) { | |||
* @return the Disposable that let's one cancel this particular delayed task. | |||
* @since 2.0 | |||
*/ | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TimeUnit
s should also receive our own non-null annotation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
static volatile Function<Single, Single> onSingleAssembly; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't remove these empty lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -664,7 +712,7 @@ public static void setOnCompletableAssembly(Function<Completable, Completable> o | |||
* @param onCompletableSubscribe the hook function to set, null allowed | |||
*/ | |||
public static void setOnCompletableSubscribe( | |||
BiFunction<Completable, CompletableObserver, CompletableObserver> onCompletableSubscribe) { | |||
@Nullable BiFunction<Completable, CompletableObserver, CompletableObserver> onCompletableSubscribe) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -761,7 +809,7 @@ public static void setOnConnectableObservableAssembly(Function<ConnectableObserv | |||
*/ | |||
@SuppressWarnings("rawtypes") | |||
public static void setOnObservableSubscribe( | |||
BiFunction<Observable, Observer, Observer> onObservableSubscribe) { | |||
@Nullable BiFunction<Observable, Observer, Observer> onObservableSubscribe) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please adjust indentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -708,14 +708,16 @@ public static Worker workerSpy(final Disposable mockDisposable) { | |||
this.mockDisposable = mockDisposable; | |||
} | |||
|
|||
@javax.annotation.Nonnull |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is worth updating the unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of "disabling" this, change it to use the thin scheduler below and assertSame
instead of null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: