Conductor: Exception while creating new instance of a Controller.

Created on 21 Aug 2016  Â·  7Comments  Â·  Source: bluelinelabs/Conductor

Hi @EricKuck, I'm using Conductor version 2.0.1 and randomly get this exception from Crashlytics so I'm afraid that I cannot create a sample for this. This IntroductionPagerController is shown when user open the app and not logged in.
Below is code how IntroductionPagerController looks like:

constructor() : super()

    constructor(bundle: Bundle) : super(bundle) {
        isRegistration = bundle.getBoolean(KEY_IS_REGISTRATION)
    }

    companion object {
        private val KEY_IS_REGISTRATION = "CreateGroupController.registration"

        fun getAuthenticationInstance(): IntroductionPagerController {
            val bundle = bundle {
                putBoolean(KEY_IS_REGISTRATION, true)
            }
            return IntroductionPagerController(bundle)
        }
    }

And the trace:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{net.localift.localift/net.localift.localift.presentation.ui.BaseActivity}: java.lang.RuntimeException: An exception occurred while creating a new instance of net.localift.localift.presentation.ui.feature.authenticate.slide.IntroductionPagerController. null
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2429)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
       at android.app.ActivityThread.access$800(ActivityThread.java:166)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5590)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096)
       at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.RuntimeException: An exception occurred while creating a new instance of net.localift.localift.presentation.ui.feature.authenticate.slide.IntroductionPagerController. null
       at com.bluelinelabs.conductor.Controller.newInstance(Controller.java:115)
       at com.bluelinelabs.conductor.RouterTransaction.<init>(RouterTransaction.java:33)
       at com.bluelinelabs.conductor.Backstack.restoreInstanceState(Backstack.java:114)
       at com.bluelinelabs.conductor.Router.restoreInstanceState(Router.java:452)
       at com.bluelinelabs.conductor.ControllerHostedRouter.restoreInstanceState(ControllerHostedRouter.java:155)
       at com.bluelinelabs.conductor.Controller.restoreInstanceState(Controller.java:981)
       at com.bluelinelabs.conductor.Controller.newInstance(Controller.java:118)
       at com.bluelinelabs.conductor.RouterTransaction.<init>(RouterTransaction.java:33)
       at com.bluelinelabs.conductor.Backstack.restoreInstanceState(Backstack.java:114)
       at com.bluelinelabs.conductor.Router.restoreInstanceState(Router.java:452)
       at com.bluelinelabs.conductor.internal.LifecycleHandler.getRouter(LifecycleHandler.java:72)
       at com.bluelinelabs.conductor.Conductor.attachRouter(Conductor.java:32)
       at net.localift.localift.presentation.ui.BaseActivity.initializeRouter(BaseActivity.kt:106)
       at net.localift.localift.presentation.ui.BaseActivity.onCreate(BaseActivity.kt:57)
       at android.app.Activity.performCreate(Activity.java:5447)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
       at android.app.ActivityThread.access$800(ActivityThread.java:166)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5590)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096)
       at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.reflect.InvocationTargetException
       at java.lang.reflect.Constructor.constructNative(Constructor.java)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
       at com.bluelinelabs.conductor.Controller.newInstance(Controller.java:109)
       at com.bluelinelabs.conductor.RouterTransaction.<init>(RouterTransaction.java:33)
       at com.bluelinelabs.conductor.Backstack.restoreInstanceState(Backstack.java:114)
       at com.bluelinelabs.conductor.Router.restoreInstanceState(Router.java:452)
       at com.bluelinelabs.conductor.ControllerHostedRouter.restoreInstanceState(ControllerHostedRouter.java:155)
       at com.bluelinelabs.conductor.Controller.restoreInstanceState(Controller.java:981)
       at com.bluelinelabs.conductor.Controller.newInstance(Controller.java:118)
       at com.bluelinelabs.conductor.RouterTransaction.<init>(RouterTransaction.java:33)
       at com.bluelinelabs.conductor.Backstack.restoreInstanceState(Backstack.java:114)
       at com.bluelinelabs.conductor.Router.restoreInstanceState(Router.java:452)
       at com.bluelinelabs.conductor.internal.LifecycleHandler.getRouter(LifecycleHandler.java:72)
       at com.bluelinelabs.conductor.Conductor.attachRouter(Conductor.java:32)
       at net.localift.localift.presentation.ui.BaseActivity.initializeRouter(BaseActivity.kt:106)
       at net.localift.localift.presentation.ui.BaseActivity.onCreate(BaseActivity.kt:57)
       at android.app.Activity.performCreate(Activity.java:5447)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
       at android.app.ActivityThread.access$800(ActivityThread.java:166)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5590)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096)
       at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter bundle
       at net.localift.localift.presentation.ui.feature.authenticate.slide.IntroductionPagerController.<init>(IntroductionPagerController.kt)
       at java.lang.reflect.Constructor.constructNative(Constructor.java)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
       at com.bluelinelabs.conductor.Controller.newInstance(Controller.java:109)
       at com.bluelinelabs.conductor.RouterTransaction.<init>(RouterTransaction.java:33)
       at com.bluelinelabs.conductor.Backstack.restoreInstanceState(Backstack.java:114)
       at com.bluelinelabs.conductor.Router.restoreInstanceState(Router.java:452)
       at com.bluelinelabs.conductor.ControllerHostedRouter.restoreInstanceState(ControllerHostedRouter.java:155)
       at com.bluelinelabs.conductor.Controller.restoreInstanceState(Controller.java:981)
       at com.bluelinelabs.conductor.Controller.newInstance(Controller.java:118)
       at com.bluelinelabs.conductor.RouterTransaction.<init>(RouterTransaction.java:33)
       at com.bluelinelabs.conductor.Backstack.restoreInstanceState(Backstack.java:114)
       at com.bluelinelabs.conductor.Router.restoreInstanceState(Router.java:452)
       at com.bluelinelabs.conductor.internal.LifecycleHandler.getRouter(LifecycleHandler.java:72)
       at com.bluelinelabs.conductor.Conductor.attachRouter(Conductor.java:32)
       at net.localift.localift.presentation.ui.BaseActivity.initializeRouter(BaseActivity.kt:106)
       at net.localift.localift.presentation.ui.BaseActivity.onCreate(BaseActivity.kt:57)
       at android.app.Activity.performCreate(Activity.java:5447)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
       at android.app.ActivityThread.access$800(ActivityThread.java:166)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5590)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096)
       at dalvik.system.NativeStart.main(NativeStart.java)

Could you suggest me how can I fix this crash? Thanks

Most helpful comment

You can just call the constructor from Java and pass null. This is
effectively the same thing as using reflection to look up the constructor
and invoke it with null which is exactly what the stacktrace indicates is
happening.

On Sun, Aug 21, 2016 at 1:03 AM Thanh Le [email protected] wrote:

I tried your suggestion to reproduce the crash, but it didn't happen.

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/bluelinelabs/Conductor/issues/102#issuecomment-241239261,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEEU53_s2CNDDtwIA4JO_E9YVbI60vks5qh9w7gaJpZM4JpOFx
.

All 7 comments

I see no issue in the code above, try to create a simple project that isolates and reproduces the issue and post it as a separate repo. Like this.

Edit: @JakeWharton is right, the issue is happening because of a kotlin null check.

Change Bundle to Bundle? in the constructor parameter type declaration.

On Sun, Aug 21, 2016 at 12:13 AM Thanh Le [email protected] wrote:

Hi @EricKuck https://github.com/EricKuck, I'm using Conductor version
2.0.1 and randomly get this exception. This IntroductionPagerController
is shown when user open the app and not logged in.
Below is code how IntroductionPagerController looks like:

constructor() : super()

constructor(bundle: Bundle) : super(bundle) {
    isRegistration = bundle.getBoolean(KEY_IS_REGISTRATION)
}

companion object {
    private val KEY_IS_REGISTRATION = "CreateGroupController.registration"

    fun getAuthenticationInstance(): IntroductionPagerController {
        val bundle = bundle {
            putBoolean(KEY_IS_REGISTRATION, true)
        }
        return IntroductionPagerController(bundle)
    }
}

And the trace:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{net.localift.localift/net.localift.localift.presentation.ui.BaseActivity}: java.lang.RuntimeException: An exception occurred while creating a new instance of net.localift.localift.presentation.ui.feature.authenticate.slide.IntroductionPagerController. null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2429)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.access$800(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5590)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.RuntimeException: An exception occurred while creating a new instance of net.localift.localift.presentation.ui.feature.authenticate.slide.IntroductionPagerController. null
at com.bluelinelabs.conductor.Controller.newInstance(Controller.java:115)
at com.bluelinelabs.conductor.RouterTransaction.(RouterTransaction.java:33)
at com.bluelinelabs.conductor.Backstack.restoreInstanceState(Backstack.java:114)
at com.bluelinelabs.conductor.Router.restoreInstanceState(Router.java:452)
at com.bluelinelabs.conductor.ControllerHostedRouter.restoreInstanceState(ControllerHostedRouter.java:155)
at com.bluelinelabs.conductor.Controller.restoreInstanceState(Controller.java:981)
at com.bluelinelabs.conductor.Controller.newInstance(Controller.java:118)
at com.bluelinelabs.conductor.RouterTransaction.(RouterTransaction.java:33)
at com.bluelinelabs.conductor.Backstack.restoreInstanceState(Backstack.java:114)
at com.bluelinelabs.conductor.Router.restoreInstanceState(Router.java:452)
at com.bluelinelabs.conductor.internal.LifecycleHandler.getRouter(LifecycleHandler.java:72)
at com.bluelinelabs.conductor.Conductor.attachRouter(Conductor.java:32)
at net.localift.localift.presentation.ui.BaseActivity.initializeRouter(BaseActivity.kt:106)
at net.localift.localift.presentation.ui.BaseActivity.onCreate(BaseActivity.kt:57)
at android.app.Activity.performCreate(Activity.java:5447)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.access$800(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5590)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.bluelinelabs.conductor.Controller.newInstance(Controller.java:109)
at com.bluelinelabs.conductor.RouterTransaction.(RouterTransaction.java:33)
at com.bluelinelabs.conductor.Backstack.restoreInstanceState(Backstack.java:114)
at com.bluelinelabs.conductor.Router.restoreInstanceState(Router.java:452)
at com.bluelinelabs.conductor.ControllerHostedRouter.restoreInstanceState(ControllerHostedRouter.java:155)
at com.bluelinelabs.conductor.Controller.restoreInstanceState(Controller.java:981)
at com.bluelinelabs.conductor.Controller.newInstance(Controller.java:118)
at com.bluelinelabs.conductor.RouterTransaction.(RouterTransaction.java:33)
at com.bluelinelabs.conductor.Backstack.restoreInstanceState(Backstack.java:114)
at com.bluelinelabs.conductor.Router.restoreInstanceState(Router.java:452)
at com.bluelinelabs.conductor.internal.LifecycleHandler.getRouter(LifecycleHandler.java:72)
at com.bluelinelabs.conductor.Conductor.attachRouter(Conductor.java:32)
at net.localift.localift.presentation.ui.BaseActivity.initializeRouter(BaseActivity.kt:106)
at net.localift.localift.presentation.ui.BaseActivity.onCreate(BaseActivity.kt:57)
at android.app.Activity.performCreate(Activity.java:5447)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.access$800(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5590)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter bundle
at net.localift.localift.presentation.ui.feature.authenticate.slide.IntroductionPagerController.(IntroductionPagerController.kt)
at java.lang.reflect.Constructor.constructNative(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.bluelinelabs.conductor.Controller.newInstance(Controller.java:109)
at com.bluelinelabs.conductor.RouterTransaction.(RouterTransaction.java:33)
at com.bluelinelabs.conductor.Backstack.restoreInstanceState(Backstack.java:114)
at com.bluelinelabs.conductor.Router.restoreInstanceState(Router.java:452)
at com.bluelinelabs.conductor.ControllerHostedRouter.restoreInstanceState(ControllerHostedRouter.java:155)
at com.bluelinelabs.conductor.Controller.restoreInstanceState(Controller.java:981)
at com.bluelinelabs.conductor.Controller.newInstance(Controller.java:118)
at com.bluelinelabs.conductor.RouterTransaction.(RouterTransaction.java:33)
at com.bluelinelabs.conductor.Backstack.restoreInstanceState(Backstack.java:114)
at com.bluelinelabs.conductor.Router.restoreInstanceState(Router.java:452)
at com.bluelinelabs.conductor.internal.LifecycleHandler.getRouter(LifecycleHandler.java:72)
at com.bluelinelabs.conductor.Conductor.attachRouter(Conductor.java:32)
at net.localift.localift.presentation.ui.BaseActivity.initializeRouter(BaseActivity.kt:106)
at net.localift.localift.presentation.ui.BaseActivity.onCreate(BaseActivity.kt:57)
at android.app.Activity.performCreate(Activity.java:5447)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.access$800(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5590)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096)
at dalvik.system.NativeStart.main(NativeStart.java)

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/bluelinelabs/Conductor/issues/102, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEEbYZLwxSGQJ7QR0HlJ6qz9QUz6E3ks5qh9BjgaJpZM4JpOFx
.

@adi1133 I just update my description, because I got this crash from Crashlytics, and it works perfectly on my devices, so I'm afraid that I cannot create a sample for this.

@JakeWharton: Thanks for your suggestion. It looks reasonable. I'll try to apply it. Will report back after few days.

The exception cause clearly indicates that this is the problem. It also
should be really easy to reproduce, you just need to do something like
rotate the phone so that Conductor recreates your controllers.

On Sun, Aug 21, 2016 at 12:26 AM Thanh Le [email protected] wrote:

@adi1133 https://github.com/adi1133 I just update my description,
because I got this crash from Crashlytics, and it works perfectly on my
devices, so I'm afraid that I cannot create a sample for this.

@JakeWharton https://github.com/JakeWharton: Thanks for your
suggestion. It looks reasonable. I'll try to apply it. Will report after
few days.

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/bluelinelabs/Conductor/issues/102#issuecomment-241238240,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEEUKlh_gkWjpXKVXFYPJw8TavSFuJks5qh9N4gaJpZM4JpOFx
.

I tried your suggestion to reproduce the crash, but it didn't happen.

You can just call the constructor from Java and pass null. This is
effectively the same thing as using reflection to look up the constructor
and invoke it with null which is exactly what the stacktrace indicates is
happening.

On Sun, Aug 21, 2016 at 1:03 AM Thanh Le [email protected] wrote:

I tried your suggestion to reproduce the crash, but it didn't happen.

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/bluelinelabs/Conductor/issues/102#issuecomment-241239261,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEEU53_s2CNDDtwIA4JO_E9YVbI60vks5qh9w7gaJpZM4JpOFx
.

Got it now, thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mradzinski picture mradzinski  Â·  5Comments

ghost picture ghost  Â·  5Comments

cbnewham picture cbnewham  Â·  8Comments

vincent-paing picture vincent-paing  Â·  6Comments

Lancelittle picture Lancelittle  Â·  10Comments