Skip to content

Crash when removing a controller on onAttach() (When it has nested Controllers) #481

@sgc-code

Description

@sgc-code

You can reproduce the issue if you try to pop a Controller from the backstack in the onAttach method. It's also needed that the Controller you are popping has a nested controller.

java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewParent android.view.View.getParent()' on a null object reference
        at com.bluelinelabs.conductor.Controller.attach(Controller.java:885)
        at com.bluelinelabs.conductor.Controller$7.onAttached(Controller.java:1029)
        at com.bluelinelabs.conductor.internal.ViewAttachHandler.reportAttached(ViewAttachHandler.java:87)
        at com.bluelinelabs.conductor.internal.ViewAttachHandler$1.onAttached(ViewAttachHandler.java:47)
        at com.bluelinelabs.conductor.internal.ViewAttachHandler$2.onViewAttachedToWindow(ViewAttachHandler.java:126)
        at android.view.View.dispatchAttachedToWindow(View.java:13536)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2688)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2695)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2695)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2695)
        at android.view.ViewGroup.addViewInner(ViewGroup.java:3975)
        at android.view.ViewGroup.addView(ViewGroup.java:3786)
        at android.view.ViewGroup.addView(ViewGroup.java:3727)
        at android.view.ViewGroup.addView(ViewGroup.java:3700)
        at com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler.performChange(SimpleSwapChangeHandler.java:73)
        at com.bluelinelabs.conductor.ControllerChangeHandler.executeChange(ControllerChangeHandler.java:204)
        at com.bluelinelabs.conductor.ControllerChangeHandler.executeChange(ControllerChangeHandler.java:154)
        at com.bluelinelabs.conductor.Router.performControllerChange(Router.java:816)
        at com.bluelinelabs.conductor.Router.performControllerChange(Router.java:786)
        at com.bluelinelabs.conductor.Router.performControllerChange(Router.java:768)
        at com.bluelinelabs.conductor.Router.popController(Router.java:137)
        at com.bluelinelabs.conductor.Router.popCurrentController(Router.java:119)
        at com.bluelinelabs.conductor.Router.handleBack(Router.java:97)
        at com.example.cnvci.conductornestedissue.MainActivity.onBackPressed(MainActivity.kt:23)

I did some debugging and I suspect it can be related to the the ViewAttachHandler, and a horrible workaround is to add an empty view as the deepest child of the parent Controller.

The ViewAttachHandler handler was written to fix a similar issue (#201), and I've also found these two issues that can be related: #407, #426

Here there's a minimal project demonstrating the issue. https://github.com/sgc-code/ConductorNestedIssue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions