Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when clicking "Collect data" again in recently added geometry #2539

Closed
jo-spek opened this issue Jul 8, 2024 · 12 comments · Fixed by #2598
Closed

Crash when clicking "Collect data" again in recently added geometry #2539

jo-spek opened this issue Jul 8, 2024 · 12 comments · Fixed by #2598
Assignees
Labels
type: bug Something isn't working

Comments

@jo-spek
Copy link
Collaborator

jo-spek commented Jul 8, 2024

Describe the bug

After having recorded a new site in my survey that does not require anything else but recording a geometry (no further questions, no photo demanded), there is a white pane at the bottom of my screen with the record's name and a green button "Collect data". If I click that button, the app crashes. This does not happen in another survey, where I can answer additional survey questions about a recorded item that I have previously skipped when I click "Collect data".
Happened on Xiaomi Poco X3 with Andoird 12 SQK1.211019.001.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new survey with nothing but one job: To walk or draw the perimeter.
  2. Draw a perimeter, give it a name and save.
  3. In the white pane with the item's name, click the green "Collect data" button again (don't swipe to the right to collect data for a new selection site, that works alright.)
  4. Crash.

Expected behavior
I don't really know. Probably not crash. Rather have the "Collect data"-button greyed out.

Actual behavior
Button is there and clickable and triggers a crash of the application.

Screenshots
Collect_data_bug

@jo-spek jo-spek added the type: bug Something isn't working label Jul 8, 2024
@shobhitagarwal1612
Copy link
Member

Pulled the stacktrace from crashlytics:

Fatal Exception: java.util.NoSuchElementException: Collection contains no element matching the predicate.
       at com.google.android.ground.ui.datacollection.DataCollectionViewModel.getTaskSequence(DataCollectionViewModel.kt:403)
       at com.google.android.ground.ui.datacollection.DataCollectionViewModel.getTaskSequence$default(DataCollectionViewModel.kt:314)
       at com.google.android.ground.ui.datacollection.DataCollectionViewModel.getPositionInTaskSequence(DataCollectionViewModel.kt:300)
       at com.google.android.ground.ui.datacollection.DataCollectionViewModel.getTaskPosition(DataCollectionViewModel.kt:343)
       at com.google.android.ground.ui.datacollection.DataCollectionViewModel.<init>(DataCollectionViewModel.kt:151)
       at com.google.android.ground.DaggerGroundApplication_HiltComponents_SingletonC$ViewModelCImpl$SwitchingProvider.get(DaggerGroundApplication_HiltComponents_SingletonC.java:1478)
       at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory$2.createViewModel(HiltViewModelFactory.java:132)
       at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory$2.create(HiltViewModelFactory.java:103)
       at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory.create(HiltViewModelFactory.java:170)
       at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.kt:184)
       at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.kt:150)
       at androidx.lifecycle.ViewModelLazy.getValue(ViewModelLazy.kt:53)
       at androidx.lifecycle.ViewModelLazy.getValue(ViewModelLazy.kt:35)
       at com.google.android.ground.ui.datacollection.DataCollectionFragment.getViewModel(DataCollectionFragment.kt:49)
       at com.google.android.ground.ui.datacollection.DataCollectionFragment.onViewCreated(DataCollectionFragment.kt:78)
       at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3147)
       at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:588)
       at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:272)
       at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1943)
       at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1845)
       at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1782)
       at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:565)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:210)
       at android.os.Looper.loop(Looper.java:299)
       at android.app.ActivityThread.main(ActivityThread.java:8319)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1038)

@jcqli jcqli added this to the Beta release (26-Jul-24 Freeze) milestone Jul 9, 2024
@gino-m
Copy link
Collaborator

gino-m commented Jul 15, 2024

@shobhitagarwal1612 @sufyanAbbasi Do you have bandwidth to take this one on in the next week or so?

@shobhitagarwal1612
Copy link
Member

I can take a first pass

@shobhitagarwal1612 shobhitagarwal1612 self-assigned this Jul 15, 2024
@gino-m
Copy link
Collaborator

gino-m commented Jul 15, 2024

Thank you, @shobhitagarwal1612

@shobhitagarwal1612
Copy link
Member

val startIndex = tasks.indexOf(tasks.first { it.id == (startId ?: tasks[0].id) })

The error is happening at line tasks.first { ... }

It is not able to find a task from the list with matching task id.

@shobhitagarwal1612
Copy link
Member

@jo-spek Are you able to reproduce this consistently? I tried reproing it but wasn't successful.

@shobhitagarwal1612
Copy link
Member

From crashlytics, I can see that it has happened 14 times in total for 3 different users.

@gino-m
Copy link
Collaborator

gino-m commented Jul 15, 2024

@jo-spek Can you please share the URL of the survey in question in private (by email)?

@jo-spek
Copy link
Collaborator Author

jo-spek commented Jul 22, 2024

@jo-spek Can you please share the URL of the survey in question in private (by email)?

I added you as a survey organizer. The name of the survey is "Test_June2024".

@gino-m
Copy link
Collaborator

gino-m commented Jul 30, 2024

val startIndex = tasks.indexOf(tasks.first { it.id == (startId ?: tasks[0].id) })

The error is happening at line tasks.first { ... }

It is not able to find a task from the list with matching task id.

The task in question was a special "add LOI" task - could that have something to do with it?

@sufyanAbbasi sufyanAbbasi self-assigned this Jul 31, 2024
@sufyanAbbasi
Copy link
Contributor

sufyanAbbasi commented Jul 31, 2024

That's very plausible. Here we construct the tasks list by filtering out the addLoiTask when we're in the predefined geometry flow:

private val tasks: List<Task> =
    if (isAddLoiFlow) job.tasksSorted else job.tasksSorted.filterNot { it.isAddLoiTask }

We determine that we're in this flow when the loidId is null:

/** True iff the user is expected to produce a new LOI in the current data collection flow. */
private val isAddLoiFlow = loiId == null

Which is determined by puling from the savedStateHandler:

private val loiId: String? = savedStateHandle[TASK_LOI_ID_KEY]

Maybe the crash happened because the LOI task is the only task, as mentioned in the repro, so we filtered the task list to empty, which was caught by @shobhitagarwal1612 PR: #2543?

Therefore, to fix this, we can just detect when we've gotten to this state and instead of starting the data collection task, we just throw the error toast: "No more tasks found for this job."

@sufyanAbbasi
Copy link
Contributor

Implemented fix above will show an error message instead of crashing: "This job has no more tasks to complete"

@gino-m gino-m removed their assignment Aug 12, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in Ground Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants