Skip to content

Crash if push another controller from onAttach() #201

@fedoretskn

Description

@fedoretskn

App crashes if push another controller form onAttach() without animation if current controller has RecyclerView in layout.

Steps to reproduce:

  1. open controller with RecyclerView in layout.
  2. push another controller from onAttach() method in the same navigation stack
  3. crash the app

Log:

FATAL EXCEPTION: main
                                                 Process: com.test.conductor.conductortest, PID: 3562
                                                 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.GapWorker.remove(android.support.v7.widget.RecyclerView)' on a null object reference
                                                     at android.support.v7.widget.RecyclerView.onDetachedFromWindow(RecyclerView.java:2479)
                                                     at android.view.View.dispatchDetachedFromWindow(View.java:14555)
                                                     at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3071)
                                                     at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3063)
                                                     at android.view.ViewGroup.removeViewInternal(ViewGroup.java:4603)
                                                     at android.view.ViewGroup.removeViewInternal(ViewGroup.java:4576)
                                                     at android.view.ViewGroup.removeView(ViewGroup.java:4507)
                                                     at com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler.performChange(SimpleSwapChangeHandler.java:69)
                                                     at com.bluelinelabs.conductor.ControllerChangeHandler.executeChange(ControllerChangeHandler.java:173)
                                                     at com.bluelinelabs.conductor.Router.performControllerChange(Router.java:652)
                                                     at com.bluelinelabs.conductor.Router.performControllerChange(Router.java:640)
                                                     at com.bluelinelabs.conductor.Router.pushController(Router.java:153)
                                                     at com.test.conductor.conductortest.controllers.ListController.onAttach(ListController.java:34)
                                                     at com.bluelinelabs.conductor.Controller.attach(Controller.java:791)
                                                     at com.bluelinelabs.conductor.Controller.access$600(Controller.java:42)
                                                     at com.bluelinelabs.conductor.Controller$7.onViewAttachedToWindow(Controller.java:903)
                                                     at android.view.View.dispatchAttachedToWindow(View.java:14525)
                                                     at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2836)
                                                     at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
                                                     at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
                                                     at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
                                                     at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
                                                     at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
                                                     at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
                                                     at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
                                                     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1364)
                                                     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
                                                     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
                                                     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
                                                     at android.view.Choreographer.doCallbacks(Choreographer.java:670)
                                                     at android.view.Choreographer.doFrame(Choreographer.java:606)
                                                     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
                                                     at android.os.Handler.handleCallback(Handler.java:739)
                                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                                     at android.os.Looper.loop(Looper.java:148)
                                                     at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

I've created test project for reproduce this issue: https://github.com/fedoretskn/conductor_list_test

It happens because onAttach() is invoked from onAttachedToWindow of parent view before was called onAttachedToWindow of RecyclerView when should be initialized gapWorker. So when the controller was detached then android calls onDetachFromWindow method of RecyclerView which calls remove() method of gapWorker which is null.

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