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

The app crashes on form finalization #6301

Closed
grzesiek2010 opened this issue Aug 1, 2024 · 0 comments · Fixed by #6302
Closed

The app crashes on form finalization #6301

grzesiek2010 opened this issue Aug 1, 2024 · 0 comments · Fixed by #6302
Assignees
Milestone

Comments

@grzesiek2010
Copy link
Member

ODK Collect version

v2024.3.0-beta.0, current master branch

Problem description

https://console.firebase.google.com/u/1/project/api-project-322300403941/crashlytics/app/android:org.odk.collect.android/issues/7ddd17ca0a93e82d425a5a441cf649de?time=last-seven-days&types=crash&versions=v2024.3.0-beta.0%20(4913)&sessionEventKey=66A3A763019F000148A7574DA36DB8A9_1974385087817821121

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List org.odk.collect.entities.javarosa.parse.EntityFormExtra.getSaveTos()' on a null object reference
	at org.odk.collect.entities.javarosa.finalization.EntityFormFinalizationProcessor.processForm(EntityFormFinalizationProcessor.java:31)
	at org.javarosa.form.api.FormEntryController.lambda$finalizeFormEntry$0$org-javarosa-form-api-FormEntryController(FormEntryController.java:210)
	at org.javarosa.form.api.FormEntryController$$ExternalSyntheticLambda0.accept(Unknown Source:4)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1642)
	at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:606)
	at org.javarosa.form.api.FormEntryController.finalizeFormEntry(FormEntryController.java:209)
	at org.odk.collect.android.javarosawrapper.JavaRosaFormController.finalizeForm(JavaRosaFormController.java:285)

Steps to reproduce the problem

  1. Install Collect v2024.2.1.
  2. Download the All question types form from the demo server.
  3. Open the form and close it.
  4. Install v2024.3.0-beta.0 or the current master branch.
  5. Open the All question types form and finalize it.

Expected behavior

There should be no crash.

What's going on?

The problem is that entityFormExtra is null after trying to read it from formDef

List<Pair<XPathReference, String>> saveTos = entityFormExtra.getSaveTos();

Then in the line below we try to use that object and get NPE.

But how null is returned instead of the expected entityFormExtra?

First of all, we need to keep in mind that we cache FormDef after opening a form for the first time. That''s what happened in the third step (see above). The cached FormDef contains extras as well.

Ok so now let's understand how we save/read extras. We do that using HashMap where the key is the class name (the fully qualified name of the class):

    public void put(T extra) {
        map.put(extra.getClass().getName(), extra);
    }

    public <U extends T> U get(Class<U> key) {
        return (U) map.get(key.getName());
    }

So in the third step using v2024.2.1 we save entityFormExtra with the key: org.javarosa.entities.internal.EntityFormExtra.
However, then we decided that EntityFormExtra class along with its whole package should be moved from Javarosa to Collect what was implemented in #6236 and became a part of v2024.3.0-beta.0.

As a result, if we now try to load such extras from cache we try to read them using org.odk.collect.entities.javarosa.parse.EntityFormExtra and get null because they exist but are stored with the old class name as a key org.javarosa.entities.internal.EntityFormExtra.

@grzesiek2010 grzesiek2010 self-assigned this Aug 1, 2024
@github-project-automation github-project-automation bot moved this to not ready in ODK Collect Aug 1, 2024
@grzesiek2010 grzesiek2010 moved this from not ready to ready in ODK Collect Aug 1, 2024
@grzesiek2010 grzesiek2010 moved this from ready to in progress in ODK Collect Aug 1, 2024
@grzesiek2010 grzesiek2010 added this to the v2024.3 milestone Aug 1, 2024
@github-project-automation github-project-automation bot moved this from in progress to done in ODK Collect Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: done
Development

Successfully merging a pull request may close this issue.

1 participant