Conductor: ConcurrentModificationException when destroying Activity

Created on 29 Sep 2016  路  4Comments  路  Source: bluelinelabs/Conductor

I'm getting randomly this Exception when closing an Activity - I think it might happen if I have a long stack of Controllers and I quickly press the back button to exit the app.

FATAL EXCEPTION: main
Process: com.invoice2go.dev, PID: 26809
java.lang.RuntimeException: Unable to destroy activity {com.invoice2go.dev/com.invoice2go.activity.MainActivity}: java.util.ConcurrentModificationException
    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3831)
    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3849)
    at android.app.ActivityThread.-wrap5(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    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)
Caused by: java.util.ConcurrentModificationException
    at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573)
    at com.bluelinelabs.conductor.ControllerHostedRouter.removeHost(ControllerHostedRouter.java:50)
    at com.bluelinelabs.conductor.Controller.removeViewReference(Controller.java:790)
    at com.bluelinelabs.conductor.Controller.detach(Controller.java:765)
    at com.bluelinelabs.conductor.Controller.destroy(Controller.java:881)
    at com.bluelinelabs.conductor.Controller.activityDestroyed(Controller.java:715)
    at com.bluelinelabs.conductor.Router.onActivityDestroyed(Router.java:424)
    at com.bluelinelabs.conductor.ActivityHostedRouter.onActivityDestroyed(ActivityHostedRouter.java:40)
    at com.bluelinelabs.conductor.internal.LifecycleHandler.destroyRouters(LifecycleHandler.java:161)
    at com.bluelinelabs.conductor.internal.LifecycleHandler.onDestroy(LifecycleHandler.java:130)
    at android.app.Fragment.performDestroy(Fragment.java:2433)
    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1098)
    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)
    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1130)
    at android.app.FragmentManagerImpl.dispatchDestroy(FragmentManager.java:1981)
    at android.app.FragmentController.dispatchDestroy(FragmentController.java:218)
    at android.app.Activity.performDestroy(Activity.java:6406)
    at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1142)
    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3818)
    ... 9 more

Looking at the code I think the way you are looping is unsafe for concurrency: I would suggest to either use a thread-safe data structure or add some synchronization logic around there (and possibly other methods that use that collection) 馃槂

Most helpful comment

New version should be live now!

All 4 comments

Surprised we hadn't come across this one yet. There was a bit of a race condition there, which is now fixed in the latest snapshot. Thanks!

Great, thanks! 馃憤
Any timeline for a main release?

I'd like to fix at least #124 first. Hopefully in the next few days.

New version should be live now!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PaulWoitaschek picture PaulWoitaschek  路  5Comments

EricKuck picture EricKuck  路  5Comments

Lancelittle picture Lancelittle  路  10Comments

lenguyenthanh picture lenguyenthanh  路  5Comments

lenguyenthanh picture lenguyenthanh  路  7Comments