Skip to content

Commit 3f0856a

Browse files
committed
1.x: negative argument check for skip's count and merge's maxConcurrent
1 parent eb39120 commit 3f0856a

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

src/main/java/rx/internal/operators/OperatorMerge.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ public static <T> OperatorMerge<T> instance(boolean delayErrors) {
8181
* @return
8282
*/
8383
public static <T> OperatorMerge<T> instance(boolean delayErrors, int maxConcurrent) {
84+
if (maxConcurrent <= 0) {
85+
throw new IllegalArgumentException("maxConcurrent > 0 required but it was " + maxConcurrent);
86+
}
8487
if (maxConcurrent == Integer.MAX_VALUE) {
8588
return instance(delayErrors);
8689
}

src/main/java/rx/internal/operators/OperatorSkip.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public final class OperatorSkip<T> implements Observable.Operator<T, T> {
3131
final int toSkip;
3232

3333
public OperatorSkip(int n) {
34+
if (n < 0) {
35+
throw new IllegalArgumentException("n >= 0 required but it was " + n);
36+
}
3437
this.toSkip = n;
3538
}
3639

src/test/java/rx/internal/operators/OperatorMergeTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,4 +1333,14 @@ public void testConcurrencyLimit() {
13331333
ts.assertValue(0);
13341334
ts.assertCompleted();
13351335
}
1336+
1337+
@Test(expected = IllegalArgumentException.class)
1338+
public void negativeMaxConcurrent() {
1339+
Observable.merge(Arrays.asList(Observable.just(1), Observable.just(2)), -1);
1340+
}
1341+
1342+
@Test(expected = IllegalArgumentException.class)
1343+
public void zeroMaxConcurrent() {
1344+
Observable.merge(Arrays.asList(Observable.just(1), Observable.just(2)), -1);
1345+
}
13361346
}

src/test/java/rx/internal/operators/OperatorSkipTest.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,9 @@
3535

3636
public class OperatorSkipTest {
3737

38-
@Test
38+
@Test(expected = IllegalArgumentException.class)
3939
public void testSkipNegativeElements() {
40-
41-
Observable<String> skip = Observable.just("one", "two", "three").lift(new OperatorSkip<String>(-99));
42-
43-
@SuppressWarnings("unchecked")
44-
Observer<String> observer = mock(Observer.class);
45-
skip.subscribe(observer);
46-
verify(observer, times(1)).onNext("one");
47-
verify(observer, times(1)).onNext("two");
48-
verify(observer, times(1)).onNext("three");
49-
verify(observer, never()).onError(any(Throwable.class));
50-
verify(observer, times(1)).onCompleted();
40+
Observable.just("one", "two", "three").skip(-99);
5141
}
5242

5343
@Test

0 commit comments

Comments
 (0)