Skip to content

Commit 5c1c4a7

Browse files
committed
Merge pull request ReactiveX#3436 from artem-zinnatullin/operator-finally-null-action-check
1.x: Add action != null check in OperatorFinally
2 parents 1af0722 + a7ed27e commit 5c1c4a7

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public final class OperatorFinally<T> implements Operator<T, T> {
3333
final Action0 action;
3434

3535
public OperatorFinally(Action0 action) {
36+
if (action == null) {
37+
throw new NullPointerException("Action can not be null");
38+
}
3639
this.action = action;
3740
}
3841

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package rx.internal.operators;
1717

18+
import static org.junit.Assert.assertEquals;
19+
import static org.junit.Assert.fail;
1820
import static org.mockito.Mockito.mock;
1921
import static org.mockito.Mockito.times;
2022
import static org.mockito.Mockito.verify;
@@ -53,4 +55,14 @@ public void testFinallyCalledOnComplete() {
5355
public void testFinallyCalledOnError() {
5456
checkActionCalled(Observable.<String> error(new RuntimeException("expected")));
5557
}
58+
59+
@Test
60+
public void nullActionShouldBeCheckedInConstructor() {
61+
try {
62+
new OperatorFinally<Object>(null);
63+
fail();
64+
} catch (NullPointerException expected) {
65+
assertEquals("Action can not be null", expected.getMessage());
66+
}
67+
}
5668
}

0 commit comments

Comments
 (0)