Skip to content

Commit

Permalink
Merge pull request #2447 from jnlopar/1.x
Browse files Browse the repository at this point in the history
Fail early if a null subscription is added to a CompositeSubscription.
  • Loading branch information
akarnokd committed Jan 21, 2015
2 parents ec60fa4 + 14fcc22 commit 2af4f74
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main/java/rx/subscriptions/CompositeSubscription.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* Copyright 2014 Netflix, Inc.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -55,6 +55,9 @@ public synchronized boolean isUnsubscribed() {
* the {@link Subscription} to add
*/
public void add(final Subscription s) {
if (s.isUnsubscribed()) {
return;
}
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 = NullPointerException.class)
public void testAddingNullSubscriptionIllegal() {
CompositeSubscription csub = new CompositeSubscription();
csub.add(null);
}

}

0 comments on commit 2af4f74

Please sign in to comment.