-
Notifications
You must be signed in to change notification settings - Fork 101
Fix crash when calling sendToView while the Presenter attaches the view #107
base: master
Are you sure you want to change the base?
Conversation
It was possible to call sendToView when the view set but a uiThreadExecutor was not. // attachView(view) ... mView = view; moveToState(State.VIEW_ATTACHED, false); ... sendToView was called after `mView = view;` on a different Thread. This fix checks both (view and mUiThreadExecutor) to be available before calling `runOnUiThread`. Additionally `sendPostponedActionsToView` will now be called when setting a new uiThreadExecutor in case a third party Presenter host has to change the uiThreadExecutor while the view is attached or attaches it after onAttachView() for some reason
I don't really get the point here. All tests are green even without your changes beside of attachView(view) {
sendToView(view -> view.something());
} is not "allowed" and leads to a crash. Whatever. Please provide at least one test which leads to a crash if you call
How can this happen? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #107 (comment)
I provided a failing test which is My workaround: Don't attach a How to reproduce this crash: The |
No. Not really. It is obviously that this test will fail. Because the I want to see a test like you describe:
Yes - maybe it is not unit testable. But we can start with implementation tests as well 👍
Maybe a stupid solution. But can't we just switch the - mView = view;
- moveToState(State.VIEW_ATTACHED, false);
+ moveToState(State.VIEW_ATTACHED, false);
+ mView = view;
- mView = view;
- moveToState(State.VIEW_ATTACHED, false);
+ moveToState(State.VIEW_ATTACHED, false);
+ notifyObservers();
+ mView = view; Additional to all: |
Apparently, its not one in a million scenario anymore, however I have actually redid something about my implementation as it seems to happen in that place only where we could simply end up with literally more than 500 commit files. I'll monitor it more with next release. Sent from my Samsung SM-G950F using FastHub Debug |
* This is a temporary field without public getter until the presenter state and notifications | ||
* get completely refactored | ||
*/ | ||
private boolean mRunning = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add volatile, will be read from multiple threads
I came to the conclusion I should remove the "multithreading" unit test. Unit test shouldn't mimic multi threading scenarios. Flip mView assignment with observer notificationsChanging the
Alternative solutionI think this boolean flag solution is a minimal as it can be. Alternatively we could synchronise Why rush?It's a bug and we can easily fix it without changing any API. I don't know when the new observer feature will be ready to be shipped. Better fix it now and replace the fix with a better solution later. |
Improve other tests to harden the current API agains future behavior changes
@passsy well, after last update it seems the issue still happening, I don't see that this will break any existing implementation for others, I hope it gets merged soon :) Sent from my Samsung SM-G950F using FastHub Debug |
@passsy @StefMa well, I guess I find my mistake. I was calling which caused the stream to be |
@k0shk0sh discovered a one in a million crash in production
It was possible to call
sendToView
when theview
is set but auiThreadExecutor
was not.sendToView
was called aftermView = view;
on a different Thread and before an observer was able to attach a executorThis fix introduces a new state
"Running"
where the view is attached and all observers are informed. Actions will be postponed until this state has been reached