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

Fail early if a null subscription is added to a CompositeSubscription. #2447

Merged
merged 4 commits into from
Jan 21, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/rx/subscriptions/CompositeSubscription.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public synchronized boolean isUnsubscribed() {
* the {@link Subscription} to add
*/
public void add(final Subscription s) {
if (s == null) {
throw new IllegalArgumentException("Added Subscription cannot be null.");
Copy link
Member

Choose a reason for hiding this comment

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

It's better to use NullPointerException. Other null assertions in RxJava throws NPE.

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! :)

}
Subscription unsubscribe = null;
synchronized (this) {
if (unsubscribed) {
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/rx/subscriptions/CompositeSubscriptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,11 @@ public void testTryRemoveIfNotIn() {

csub.remove(csub1); // try removing agian
}

@Test(expected = IllegalArgumentException.class)
public void testAddingNullSubscriptionIllegal() {
CompositeSubscription csub = new CompositeSubscription();
csub.add(null);
Copy link
Member

Choose a reason for hiding this comment

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

Indentation should be four spaces here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks!

}

}