Skip to content
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

Container is null in performControllerChange when back button is pressed #337

Open
jamieadkins95 opened this issue Aug 2, 2017 · 8 comments

Comments

@jamieadkins95
Copy link

We are getting a unreproducible crash report in our app that's difficult to find the cause of.

It appears the container is null when performControllerChange is called in Router.java:

container.post(new Runnable() {
                @Override
                public void run() {
                    performPendingControllerChanges();
                }
            });

Full stack trace:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.view.View.post(java.lang.Runnable)' on a null object reference
       at com.bluelinelabs.conductor.Router.performControllerChange(SourceFile:767)
       at com.bluelinelabs.conductor.Router.performControllerChange(SourceFile:744)
       at com.bluelinelabs.conductor.Router.performControllerChange(SourceFile:726)
       at com.bluelinelabs.conductor.Router.popController(SourceFile:136)
       at com.bluelinelabs.conductor.Router.popCurrentController(SourceFile:118)
       at com.bluelinelabs.conductor.Router.handleBack(SourceFile:96)
       at com.redacted.redacted.MainController.handleBack(SourceFile:147)
       at com.bluelinelabs.conductor.Router.handleBack(SourceFile:94)
       at com.redacted.redacted.MainActivity.onBackPressed(SourceFile:103)
       at android.app.Activity.onKeyUp(Activity.java:2826)
       at android.view.KeyEvent.dispatch(KeyEvent.java:2766)
       at android.app.Activity.dispatchKeyEvent(Activity.java:3146)
       at android.support.v7.app.AppCompatActivity.dispatchKeyEvent(SourceFile:541)
       at android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(SourceFile:59)
       at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(SourceFile:319)
       at com.android.internal.policy.DecorView.dispatchKeyEvent(DecorView.java:353)
       at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4742)
       at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4713)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4249)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4302)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4268)
       at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4395)
       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4276)
       at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4452)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4249)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4302)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4268)
       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4276)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4249)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4302)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4268)
       at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4428)
       at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4589)
       at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2512)
       at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:2106)
       at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:2097)
       at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2487)
       at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
       at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
       at android.os.MessageQueue.next(MessageQueue.java:346)
       at android.os.Looper.loop(Looper.java:138)
       at android.app.ActivityThread.main(ActivityThread.java:6523)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)

I can't seem to reproduce it, so I suspect it occurs during some weird state where the back button is pressed while the container view isn't quite ready. Strangely, it gets past your containerFullyAttached check.

Have you got any idea about what state the app has to be in to cause this issue? I know changes have been made recently in this part of the library, so this may be related to #287 #285 and this commit.

@jamieadkins95
Copy link
Author

Infact, we are only seeing this issue in the version that upgraded from 2.1.3 to 2.1.4

@chris6647
Copy link

I'm seeing the same issue, but I am messing about with the instance state of the backstack (related to #316 ).
I am, however, able to make it happen at will. I don't quite get the finer details, yet, but It occurs when I'm a few levels into in that Router's backstack, and my current Controller is inside a nested Controller flow, and I attempt to clear the my main content Router.

Below is another stacktrack, which originates from the same place in my code, and seems to have relevance to this issue:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.bluelinelabs.conductor.Controller.getChildRouters()' on a null object reference
    at com.bluelinelabs.conductor.ControllerHostedRouter.getSiblingRouters(ControllerHostedRouter.java:223)
    at com.bluelinelabs.conductor.Router.removeAllExceptVisibleAndUnowned(Router.java:819)
    at com.bluelinelabs.conductor.Router.setBackstack(Router.java:406)
    at com.bluelinelabs.conductor.ControllerHostedRouter.setBackstack(ControllerHostedRouter.java:106)
    at com.bluelinelabs.conductor.Router.setRoot(Router.java:333)

@TheLester
Copy link

Same issue here.

@EricKuck
Copy link
Member

Does anyone have more info on this? A way to reproduce it would be great.

@hunter-t
Copy link

hunter-t commented Aug 12, 2019

This issue is returned back in version 2.1.5.

@danielocampo2
Copy link

danielocampo2 commented Mar 12, 2020

It is happening for me as well and it is very easy to reproduce (for me at least).

  1. Open the app - MainActivity will attachRouter and setRoot.
  2. Press back as in to close the app (when you do this, app is not killed by OS).
  3. Open the app again. MainActivity will attachRouter and setRoot again, but I believe it will re-use some cached instances, that are probably in an incorrect state.
  4. Try to open any other screen / whatever that will push a new controller.

Expected
5. New screen is shown as usual.

Actual
5. App crashes with said exception:
Attempt to invoke virtual method 'boolean android.view.ViewGroup.post(java.lang.Runnable)' on a null object reference

I am pretty sure this has to do with Conductor's router keeping the wrong state and assuming it can re-use what it already has, but some things are null / were cleared up, something like that.
It is a very common usecase that I haven't yet been able to find a workaround.

Is there any way to clear the cache or re-create the router?

I am using 3.0.1-SNAPSHOT version.

Thanks.

@PaulWoitaschek
Copy link
Collaborator

@danielocampo2
Share a minimal, reproducible, self-contained example.That would greatly help locate the issue.

@danielocampo2
Copy link

@PaulWoitaschek tdigging into the demo and comparing I realized it was actually a DI issue.
The router was being recreated but my Navigator class was using an old instance.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants