-
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
More nullability annotations #5251
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,14 @@ | |
*/ | ||
package io.reactivex.disposables; | ||
|
||
import java.util.*; | ||
|
||
import io.reactivex.annotations.NonNull; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't unroll star imports. |
||
import io.reactivex.exceptions.*; | ||
import io.reactivex.internal.disposables.DisposableContainer; | ||
import io.reactivex.internal.functions.ObjectHelper; | ||
import io.reactivex.internal.util.*; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* A disposable container that can hold onto multiple other disposables and | ||
* offers O(1) add and removal complexity. | ||
|
@@ -39,7 +40,7 @@ public CompositeDisposable() { | |
* Creates a CompositeDisposables with the given array of initial elements. | ||
* @param resources the array of Disposables to start with | ||
*/ | ||
public CompositeDisposable(Disposable... resources) { | ||
public CompositeDisposable(@NonNull Disposable... resources) { | ||
ObjectHelper.requireNonNull(resources, "resources is null"); | ||
this.resources = new OpenHashSet<Disposable>(resources.length + 1); | ||
for (Disposable d : resources) { | ||
|
@@ -52,7 +53,7 @@ public CompositeDisposable(Disposable... resources) { | |
* Creates a CompositeDisposables with the given Iterable sequence of initial elements. | ||
* @param resources the Iterable sequence of Disposables to start with | ||
*/ | ||
public CompositeDisposable(Iterable<? extends Disposable> resources) { | ||
public CompositeDisposable(@NonNull Iterable<? extends Disposable> resources) { | ||
ObjectHelper.requireNonNull(resources, "resources is null"); | ||
this.resources = new OpenHashSet<Disposable>(); | ||
for (Disposable d : resources) { | ||
|
@@ -85,7 +86,7 @@ public boolean isDisposed() { | |
} | ||
|
||
@Override | ||
public boolean add(Disposable d) { | ||
public boolean add(@NonNull Disposable d) { | ||
ObjectHelper.requireNonNull(d, "d is null"); | ||
if (!disposed) { | ||
synchronized (this) { | ||
|
@@ -110,7 +111,7 @@ public boolean add(Disposable d) { | |
* @param ds the array of Disposables | ||
* @return true if the operation was successful, false if the container has been disposed | ||
*/ | ||
public boolean addAll(Disposable... ds) { | ||
public boolean addAll(@NonNull Disposable... ds) { | ||
ObjectHelper.requireNonNull(ds, "ds is null"); | ||
if (!disposed) { | ||
synchronized (this) { | ||
|
@@ -135,7 +136,7 @@ public boolean addAll(Disposable... ds) { | |
} | ||
|
||
@Override | ||
public boolean remove(Disposable d) { | ||
public boolean remove(@NonNull Disposable d) { | ||
if (delete(d)) { | ||
d.dispose(); | ||
return true; | ||
|
@@ -144,7 +145,7 @@ public boolean remove(Disposable d) { | |
} | ||
|
||
@Override | ||
public boolean delete(Disposable d) { | ||
public boolean delete(@NonNull Disposable d) { | ||
ObjectHelper.requireNonNull(d, "Disposable item is null"); | ||
if (disposed) { | ||
return false; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
*/ | ||
package io.reactivex.disposables; | ||
|
||
import io.reactivex.annotations.Nullable; | ||
|
||
import java.util.concurrent.Future; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
|
@@ -24,7 +26,7 @@ final class FutureDisposable extends AtomicReference<Future<?>> implements Dispo | |
|
||
private final boolean allowInterrupt; | ||
|
||
FutureDisposable(Future<?> run, boolean allowInterrupt) { | ||
FutureDisposable(@Nullable Future<?> run, boolean allowInterrupt) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-public components don't really need this annotation. |
||
super(run); | ||
this.allowInterrupt = allowInterrupt; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,11 @@ | |
|
||
package io.reactivex.disposables; | ||
|
||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import io.reactivex.annotations.NonNull; | ||
import io.reactivex.internal.functions.ObjectHelper; | ||
|
||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
/** | ||
* Base class for Disposable containers that manage some other type that | ||
* has to be run when the container is disposed. | ||
|
@@ -27,11 +28,11 @@ abstract class ReferenceDisposable<T> extends AtomicReference<T> implements Disp | |
|
||
private static final long serialVersionUID = 6537757548749041217L; | ||
|
||
ReferenceDisposable(T value) { | ||
ReferenceDisposable(@NonNull T value) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-public components don't need this annotation. |
||
super(ObjectHelper.requireNonNull(value, "value is null")); | ||
} | ||
|
||
protected abstract void onDisposed(T value); | ||
protected abstract void onDisposed(@NonNull T value); | ||
|
||
@Override | ||
public final void dispose() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,19 +12,21 @@ | |
*/ | ||
package io.reactivex.disposables; | ||
|
||
import io.reactivex.annotations.NonNull; | ||
|
||
/** | ||
* A disposable container that manages a Runnable instance. | ||
*/ | ||
final class RunnableDisposable extends ReferenceDisposable<Runnable> { | ||
|
||
private static final long serialVersionUID = -8219729196779211169L; | ||
|
||
RunnableDisposable(Runnable value) { | ||
RunnableDisposable(@NonNull Runnable value) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-public... |
||
super(value); | ||
} | ||
|
||
@Override | ||
protected void onDisposed(Runnable value) { | ||
protected void onDisposed(@NonNull Runnable value) { | ||
value.run(); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
*/ | ||
package io.reactivex.disposables; | ||
|
||
import io.reactivex.annotations.NonNull; | ||
import org.reactivestreams.Subscription; | ||
|
||
/** | ||
|
@@ -21,12 +22,12 @@ final class SubscriptionDisposable extends ReferenceDisposable<Subscription> { | |
|
||
private static final long serialVersionUID = -707001650852963139L; | ||
|
||
SubscriptionDisposable(Subscription value) { | ||
SubscriptionDisposable(@NonNull Subscription value) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-public... |
||
super(value); | ||
} | ||
|
||
@Override | ||
protected void onDisposed(Subscription value) { | ||
protected void onDisposed(@NonNull Subscription value) { | ||
value.cancel(); | ||
} | ||
} |
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.
Non-public components don't really need such annotations.