projectbuendia / client

Android client app
Apache License 2.0
38 stars 23 forks source link

All present patients shows "No patients" #206

Open dancunningham opened 8 years ago

dancunningham commented 8 years ago

This is after a crash and app restart due to #199.

On the locations screen it showed that there are 27 patients in "All present patients" but when I open it, it says "No patients".

I know that there are patients.

Doing a pull down refresh brought them in.

But that is a scary thing to see - it looks like all the patients have been deleted.

The patient list loading code needs to be more resilient.

llvasconcellos commented 8 years ago

@dancunningham: I saw this happening once or twice but it's intermittent and will be hard to reproduce it.

llvasconcellos commented 8 years ago

I just saw it happening again. I only have one patient in the server. I force closed the app and cleared its data using android setup. I opened the app, went to settings and switched to my local server IP and then logged in. Right after initial sync finished I clicked on all patients and it showed the message "No Patients" just to right after dismiss it and show the patient.

capnfabs commented 8 years ago

Race condition for sure.

capnfabs commented 8 years ago

This won't happen before v1, moving to post-pilot.

capnfabs commented 8 years ago

Dan just found this crash:

FATAL EXCEPTION: main
Process: org.projectbuendia.client.dev, PID: 8648
java.lang.NullPointerException: Attempt to read from null array
    at org.projectbuendia.client.ui.PatientListTypedCursorAdapter.getGroup(PatientListTypedCursorAdapter.java:120)
    at org.projectbuendia.client.ui.PatientListTypedCursorAdapter.getChildrenCount(PatientListTypedCursorAdapter.java:124)
    at android.widget.ExpandableListConnector.refreshExpGroupMetadataList(ExpandableListConnector.java:563)
    at android.widget.ExpandableListConnector.expandGroup(ExpandableListConnector.java:688)
    at android.widget.ExpandableListView.expandGroup(ExpandableListView.java:753)
    at android.widget.ExpandableListView.expandGroup(ExpandableListView.java:737)
    at org.projectbuendia.client.widgets.GroupedListView.expandAllGroups(GroupedListView.java:70)
    at org.projectbuendia.client.widgets.GroupedListView.access$000(GroupedListView.java:31)
    at org.projectbuendia.client.widgets.GroupedListView$2.onChanged(GroupedListView.java:63)
    at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
    at android.widget.BaseExpandableListAdapter.notifyDataSetChanged(BaseExpandableListAdapter.java:56)
    at org.projectbuendia.client.ui.PatientListTypedCursorAdapter$FetchObservationsTask.onPostExecute(PatientListTypedCursorAdapter.java:259)
    at org.projectbuendia.client.ui.PatientListTypedCursorAdapter$FetchObservationsTask.onPostExecute(PatientListTypedCursorAdapter.java:251)
    at android.os.AsyncTask.finish(AsyncTask.java:636)
    at android.os.AsyncTask.access$500(AsyncTask.java:177)
    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:211)
    at android.app.ActivityThread.main(ActivityThread.java:5373)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)

Suspect that these are related, and "no patients" happens when you click the "All Patients" button, but this crash happens when you click a different location, when the PatientListTypedCursorAdapter is in the same erroneous state.

capnfabs commented 8 years ago

The issue here appears to be that the PatientSearchController is waiting for a TypedCursorFetchedEvent<Patient> before it updates the patients.

It's not clear yet whether this event is happening too early or too late, I'll keep digging. Either way, this would result in "No patients" found if you don't select a filter, or the above exception if you do select a filter.