uservoice / uservoice-android-sdk

UserVoice Android SDK
https://www.uservoice.com/mobile/
MIT License
116 stars 105 forks source link

Nullpointer in TopicActivity #211

Open TepesLucian opened 8 years ago

TepesLucian commented 8 years ago

I see this crash from crashlytics. Any ideas why is this crash occurring?

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jane.android/com.uservoice.uservoicesdk.activity.TopicActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2661) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) at android.app.ActivityThread.access$900(ActivityThread.java:172) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5835) 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:1399) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) Caused by java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference at android.widget.ArrayAdapter.getCount(ArrayAdapter.java:330) at android.widget.AbsSpinner.setAdapter(AbsSpinner.java:118) at android.widget.Spinner.setAdapter(Spinner.java:451) at android.support.v7.widget.AppCompatSpinner.setAdapter(AppCompatSpinner.java:383) at android.support.v7.internal.widget.ToolbarWidgetWrapper.setDropdownParams(ToolbarWidgetWrapper.java:541) at android.support.v7.internal.app.WindowDecorActionBar.setListNavigationCallbacks(WindowDecorActionBar.java:1238) at com.uservoice.uservoicesdk.activity.TopicActivity.onCreate(TopicActivity.java:38) at android.app.Activity.performCreate(Activity.java:6221) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2614) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) at android.app.ActivityThread.access$900(ActivityThread.java:172) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5835) 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:1399) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

TepesLucian commented 8 years ago

@banane @austintaylor any thoughts on this one?

martyglaubitz commented 8 years ago

we're also getting this. just a different stacktrace java.lang.RuntimeException: Unable to start activity ComponentInfo{my.app/com.uservoice.uservoicesdk.activity.TopicActivity}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2118) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2145) at android.app.ActivityThread.access$600(ActivityThread.java:130) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1211) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4847) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:535) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at android.widget.ArrayAdapter.getCount(ArrayAdapter.java:330) at android.widget.AbsSpinner.setAdapter(AbsSpinner.java:114) at android.widget.Spinner.setAdapter(Spinner.java:371) at android.support.v7.widget.AppCompatSpinner.setAdapter(AppCompatSpinner.java:391) at android.support.v7.widget.ToolbarWidgetWrapper.setDropdownParams(ToolbarWidgetWrapper.java:537) at android.support.v7.app.WindowDecorActionBar.setListNavigationCallbacks(WindowDecorActionBar.java:1249) at com.uservoice.uservoicesdk.activity.TopicActivity.onCreate(TopicActivity.java:38) at android.app.Activity.performCreate(Activity.java:5187) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064) ... 11 more

davethomas11 commented 7 years ago

I am also noticing this crash in our crash logs as well. Mind you it is rare.

I've checked out the uservoice-android-sdk and have researched the cause of this crash. I am able to reproduce the crash.

It is a fairly complex edge case and is probably the aggravator for other similar issues with in this SDK.

The null pointer happens to the Session class which is instantiated as a singleton in static memory. The problem is this static memory will be cleared when the system kills the application process. This can happen at any time on Android without your control.

If the app is backgrounded and currently at a TopicActivity when the OS kills the app if the user returns to the app it will crash. The OS will relaunch the app starting at the previous TopicActivity and because Session.topics never gets initialized at this point in the code you will get a null pointer exception when accessing the topics list.

To recreate this bug, and simulate the OS killing your application use the Android Device Monitor. Navigate to a TopicActivity, background the application, and in ADM select your app's process and click the stop button. Then on the device go to your backgrounded apps quick start, and restart the app. Notice the same crash log.