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

Feature/#4876 nonnull annotations #5051

Merged

Conversation

jschneider
Copy link
Contributor

@jschneider jschneider commented Feb 2, 2017

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:

  • use jsr305 (compileOnly) or existing annotation in io.reactivex?
  • (if not using jsr305): Use own @nullable annotation or try to get one added to "io.reactivex"? Or skip these completely (which misses the point of the static code analysis)
  • Why has there been tests calling the RxJavaPlugins.on*Scheduler with null arguments? Can these be removed securely?

@akarnokd
Copy link
Member

akarnokd commented Feb 2, 2017

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.

I decided to add a compileOnly dependency to findbugs:jsr305 artifact.

We rather use our own annotations as most tools allow customizing what annotations to consider.

Expect futher comments inline.

Copy link
Member

@akarnokd akarnokd left a 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TimeUnits should also receive our own non-null annotation.

Copy link
Contributor Author

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;

Copy link
Member

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.

Copy link
Contributor Author

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation

Copy link
Contributor Author

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please adjust indentation.

Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Contributor Author

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));
Copy link
Member

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.

Copy link
Contributor Author

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.

@jschneider
Copy link
Contributor Author

Thanks for the feedback. I will improve the pull request further.

@akarnokd akarnokd added this to the 2.1 milestone Feb 3, 2017
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.CLASS;

@Documented
Copy link
Member

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?

@jschneider jschneider force-pushed the feature/#4876-nonnull-annotations branch 4 times, most recently from 6717518 to 8e8978c Compare February 3, 2017 10:06
@jschneider jschneider force-pushed the feature/#4876-nonnull-annotations branch from 8e8978c to ab7e287 Compare February 3, 2017 10:10
@akarnokd akarnokd merged commit 8720828 into ReactiveX:2.x Feb 3, 2017
@jschneider jschneider deleted the feature/#4876-nonnull-annotations branch February 3, 2017 11:21
@akarnokd akarnokd mentioned this pull request Mar 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants