-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OperatorFinally calls action twice if action throws exception. Exception thrown by action is swallowed #3435
Comments
Here are the tests: @Test
public void nullFinallyActionShouldBeCheckedASAP() {
try {
Observable
.just("value")
.finallyDo(null);
fail();
} catch (NullPointerException expected) {
}
}
@Test
public void ifFinallyActionThrowsExceptionShouldNotBeSwallowedAndActionShouldBeCalledOnce() {
Action0 finallyAction = mock(Action0.class);
doThrow(new IllegalStateException()).when(finallyAction).call();
TestSubscriber<String> testSubscriber = new TestSubscriber<String>();
Observable
.just("value")
.finallyDo(finallyAction)
.subscribe(testSubscriber);
testSubscriber.assertValue("value");
verify(finallyAction).call();
// Actual result:
// Not only IllegalStateException was swallowed
// But finallyAction was called twice!
} |
I'll try to send PRs with fixes ASAP, |
If the action throws, you can't do much but call |
We can throw it as |
The sequence has already terminated at that point and this operator is there to have side-effects after it. The exception has nowhere to go and there is no guarantee a thrown error reaches its intended target because of a potential async boundary. So it either propagates up to a synchronous caller, gets thrown away by the |
Can this be closed? |
@akarnokd won't be able to work on this for at least 2 days, feel free to run the tests I posted ^ and see what we can do here or I'll investigate this in the end of the week. As far as I remember, the biggest problem is that |
Fix posted in #3823. |
Closing via #3823 |
While I was implementing #3434 I've found two problems with
OperatorFinally
.I'll call
OperatorFinally.action
asfinallyAction
for better readability.finallyAction
isnull
—NullPointerException
will be swallowed bySafeSubscriber
, this can be solved viaaction != null
check in theOperatorFinally
(I'll make PR).finallyAction
throws exception,lift
callsonError()
andOperatorFinally
invokesfinallyAction
again (this may brake user-defined logic)! And second exception is swallowed by theSafeSubscriber
(see problem 1).I vote for solving both of these problems before 1.0.15/1.1.10.
The text was updated successfully, but these errors were encountered: