uservoice / uservoice-android-sdk

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

Fix an NPE in getDetailRows in PostIdeaAdapter #273

Closed nealsanche closed 5 years ago

nealsanche commented 5 years ago

We were seeing the following crash:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.uservoice.uservoicesdk.model.Forum.getCategories()' on a null object reference
       at com.uservoice.uservoicesdk.ui.PostIdeaAdapter.getDetailRows(PostIdeaAdapter.java:52)
       at com.uservoice.uservoicesdk.ui.InstantAnswersAdapter.getRows(InstantAnswersAdapter.java:94)
       at com.uservoice.uservoicesdk.ui.PostIdeaAdapter.getRows(PostIdeaAdapter.java:62)
       at com.uservoice.uservoicesdk.ui.InstantAnswersAdapter.getCount(InstantAnswersAdapter.java:106)
       at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:836)
       at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:6421)
       at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
       at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:52)
       at com.uservoice.uservoicesdk.ui.InstantAnswersAdapter.onButtonTapped(InstantAnswersAdapter.java:298)
       at com.uservoice.uservoicesdk.ui.InstantAnswersAdapter$1.onClick(InstantAnswersAdapter.java:163)
       at android.view.View.performClick(View.java:6597)
       at android.view.View.performClickInternal(View.java:6574)
       at android.view.View.access$3100(View.java:778)
       at android.view.View$PerformClick.run(View.java:25885)
       at android.os.Handler.handleCallback(Handler.java:873)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:193)
       at android.app.ActivityThread.main(ActivityThread.java:6669)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

This PR is a patch only, to avoid this particular crash. Unfortunately due to the async nature of the design of this SDK it's possible to have crashes in a number of different places where the data has not yet loaded. So, it's not a long-term solution.

The remainder of the changes were in order to make the library build on jitpack which was used to test the deployment. It updates to the newest Android API and recent support library. (pre AndroidX)