Android SDK crash report: NPE on InputFragment.setArguments

#1

Hi. I’m getting the following bug reported on Crashlytics on our app on the latest SDK

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.Bundle.unparcel()' on a null object reference
       at android.os.Bundle.putAll(Bundle.java:182)
       at com.intercom.composer.input.InputFragment.setArguments(InputFragment.java:38)
       at androidx.fragment.app.FragmentState.instantiate(FragmentState.java:78)
       at androidx.fragment.app.FragmentManagerImpl.restoreSaveState(FragmentManagerImpl.java:2456)
       at androidx.fragment.app.Fragment.restoreChildFragmentState(Fragment.java:1534)
       at androidx.fragment.app.Fragment.onCreate(Fragment.java:1507)
       at com.intercom.composer.ComposerFragment.onCreate(ComposerFragment.java:79)
       at androidx.fragment.app.Fragment.performCreate(Fragment.java:2414)
       at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:844)
       at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1229)
       at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1295)
       at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManagerImpl.java:2605)
       at androidx.fragment.app.FragmentManagerImpl.dispatchCreate(FragmentManagerImpl.java:2559)
       at androidx.fragment.app.Fragment.restoreChildFragmentState(Fragment.java:1535)
       at androidx.fragment.app.Fragment.onCreate(Fragment.java:1507)
       at io.intercom.android.sdk.conversation.ConversationFragment.onCreate(ConversationFragment.java:177)
       at androidx.fragment.app.Fragment.performCreate(Fragment.java:2414)
       at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:844)
       at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1229)
       at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1295)
       at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManagerImpl.java:2605)
       at androidx.fragment.app.FragmentManagerImpl.dispatchCreate(FragmentManagerImpl.java:2559)
       at androidx.fragment.app.FragmentController.dispatchCreate(FragmentController.java:234)
       at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:304)
       at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:85)
       at io.intercom.android.sdk.activities.IntercomMessengerActivity.onCreate(IntercomMessengerActivity.java:75)
       at android.app.Activity.performCreate(Activity.java:6550)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3077)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3233)
       at android.app.ActivityThread.access$1000(ActivityThread.java:197)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6873)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

Its not clear to know where this is being caused (as its just a Crashlytics report with no clear source). But in various places in the app we use the following Intercom calls:

Intercom.client().displayHelpCenter();
Intercom.client().displayMessenger();
Intercom.client().registerIdentifiedUser(registration);
Intercom.client().displayConversationsList();
Intercom.client().registerIdentifiedUser(Registration.create().withUserId(userToken.userId))
Intercom.client().logout()
Intercom.client().displayMessageComposer()

As I told Joel in an email

if you look at android.support.v4.app.Fragment - you’ll see the method > public void setArguments(@Nullable Bundle args)

the argument is nullable, but your InputFragment’s override treats it as though it is non-null, and hence, the following code inside the class causes a NPE when the argument is a null

@Override public void setArguments(Bundle newArgs) {

    Bundle existingArgs = getArguments();

    if (existingArgs == null) {

        existingArgs = new Bundle();

    }

    existingArgs.putAll(newArgs);

    super.setArguments(existingArgs);

}
0 Likes

#2

I’ve also faced this issue in our app, and it was similarly reported by Crashlytics without us being able to replicate it in use. Were you able to find any fix to this?

0 Likes

#3

the SDK has to be fixed by Intercom devs - its a fairly simple fix (a null check) and I sent it to customer services the same time I reported the issue here but I don’t know how long it takes them to get around to fixing things

0 Likes

#4

Hey all,

Appreciate you both passing this in - we do currently have an issue around this open. While I can’t give a hard timeline at this moment, I can promise we’re looking at getting this resolved. :+1:

0 Likes

#5

Thanks for the update @joel.williams. Meanwhile, is there something we can do from our end to mitigate the crashes? For example, is there a way to pass an empty newArgs Bundle to avoid the crash, or is that handled internally.

0 Likes

#6

There’s not, as shown by the stack-trace these are all methods called by the fragment lifecycle. So the fragment class InputFragment has to be fixed.

In the last 30 days I’ve had 65 crashes from 50 users.

The fix is the most simple thing in the world but as the SDK isn’t open-source I’m having to search on how to decompile and recompile the package.

0 Likes