Skip to content

Commit 2af4f74

Browse files
committed
Merge pull request #2447 from jnlopar/1.x
Fail early if a null subscription is added to a CompositeSubscription.
2 parents ec60fa4 + 14fcc22 commit 2af4f74

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2014 Netflix, Inc.
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -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.isUnsubscribed()) {
59+
return;
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 = NullPointerException.class)
342+
public void testAddingNullSubscriptionIllegal() {
343+
CompositeSubscription csub = new CompositeSubscription();
344+
csub.add(null);
345+
}
346+
340347
}

0 commit comments

Comments
 (0)