Skip to content

Commit 5154351

Browse files
committed
Fail early if a null subscription is added to a CompositeSubscription.
Otherwise, it'll just fail late when unsubscribing, which is much harder to trace.
1 parent b37c7ed commit 5154351

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/main/java/rx/subscriptions/CompositeSubscription.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public synchronized boolean isUnsubscribed() {
5555
* the {@link Subscription} to add
5656
*/
5757
public void add(final Subscription s) {
58+
if (s == null) {
59+
throw new IllegalArgumentException("Added Subscription cannot be null.");
60+
}
5861
Subscription unsubscribe = null;
5962
synchronized (this) {
6063
if (unsubscribed) {

src/test/java/rx/subscriptions/CompositeSubscriptionTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,11 @@ public void testTryRemoveIfNotIn() {
337337

338338
csub.remove(csub1); // try removing agian
339339
}
340+
341+
@Test(expected = IllegalArgumentException.class)
342+
public void testAddingNullSubscriptionIllegal() {
343+
CompositeSubscription csub = new CompositeSubscription();
344+
csub.add(null);
345+
}
346+
340347
}

0 commit comments

Comments
 (0)