diff --git a/src/main/java/rx/subscriptions/CompositeSubscription.java b/src/main/java/rx/subscriptions/CompositeSubscription.java index fea7b70910..777b18f04d 100644 --- a/src/main/java/rx/subscriptions/CompositeSubscription.java +++ b/src/main/java/rx/subscriptions/CompositeSubscription.java @@ -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. @@ -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) { diff --git a/src/test/java/rx/subscriptions/CompositeSubscriptionTest.java b/src/test/java/rx/subscriptions/CompositeSubscriptionTest.java index 4cff2a3e6a..18ac45f198 100644 --- a/src/test/java/rx/subscriptions/CompositeSubscriptionTest.java +++ b/src/test/java/rx/subscriptions/CompositeSubscriptionTest.java @@ -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); + } + }