cbeyls / fosdem-companion-android

FOSDEM Companion for Android
Apache License 2.0
136 stars 93 forks source link

Fatal crash - NullPointerException: Attempt to read from field 'androidx.recyclerview.widget.RecyclerView be.digitalia.fosdem.fragments.RecyclerViewFragment$ViewHolder.recyclerView' on a null object reference #59

Closed tingsu closed 4 years ago

tingsu commented 4 years ago

Hi,

Recently, I tested fosdem (v1.6.2) and encountered a fatal crash multuiple times. I tried to reproduce this issue with the action traces dumped by my testing tool, but I cannot reproduce it deterministically (also on the latest version v2.0.1). I guess the root cause may be related to the timing of actions. I posted the issue here. Let me know if you need more info. Thanks.

Event traces

20200408_162349

GUI page where the crash happens (this crash happens after the last action in the above video was executed)

Stack trace:

 FATAL EXCEPTION: main
 Process: be.digitalia.fosdem, PID: 12643
 java.lang.NullPointerException: Attempt to read from field 'androidx.recyclerview.widget.RecyclerView be.digitalia.fosdem.fragments.RecyclerViewFragment$ViewHolder.recyclerView' on a null object reference
    at be.digitalia.fosdem.fragments.RecyclerViewFragment.getRecyclerView(RecyclerViewFragment.java:129)
    at be.digitalia.fosdem.fragments.BaseLiveListFragment$1.run(BaseLiveListFragment.java:54)
    at androidx.paging.AsyncPagedListDiffer.onCurrentListChanged(AsyncPagedListDiffer.java:403)
    at androidx.paging.AsyncPagedListDiffer.latchPagedList(AsyncPagedListDiffer.java:392)
    at androidx.paging.AsyncPagedListDiffer$2$1.run(AsyncPagedListDiffer.java:345)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    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)
cbeyls commented 4 years ago

Thank you for your report!

According to the stack trace you provided, the problem was caused by a null ViewHolder in BaseLiveListFragment or RecyclerViewFragment without a proper null check. As far as I can tell, this may not happen in version 2.0.1 since the Kotlin code properly checks for null in both classes.

I also recently refactored the way ViewHolders and Views are accessed in fragments to avoid this kind of problems so I believe the bug has already been fixed.

Can you test the version on the master branch to confirm there is no more bug, and open a new issue with the correct stack trace if you still manage to reproduce it? Thank you.

cbeyls commented 4 years ago

Note: It looks like the null check is also present in version 1.7.3. So only version 1.6.2 could crash with that stack trace.

tingsu commented 4 years ago

Thanks for your confirmation and reply, @cbeyls ! Yes, I noted you very recently refactored this part. I will try to test on the master version again to see whether this issue still exists. Thanks.