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

Prevent NullPointerExceptions when the activity is null #2982

Merged
merged 1 commit into from
Apr 2, 2019

Conversation

lognaturel
Copy link
Member

@lognaturel lognaturel commented Apr 2, 2019

Closes #2979

What has been done to verify that this works as intended?

I rotated the screen quickly on first launch of a geo widget using Google Maps and kept doing it over and over again. I believe the issue could occur not just when first launching the question but whenever a location update was received at the same time as an orientation change. It's just easiest to reproduce on first launch.

Why is this the best possible solution? Were any other approaches considered?

I considered doing the check on getActivity() being null deeper in the code but this ended up making the most sense to me: only update the location indicator if the activity exists. The other null check in createMarker is probably not strictly necessary but I couldn't quickly convince myself that the activity could never be null there so I figured it's better to be defensive.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

It only fixes the bug. If the activity is null, users can't see anything anyway so this won't affect them.

Do we need any specific form for testing your changes? If so, please attach one.

Any form with geo widgets.

Does this change require updates to documentation? If so, please file an issue here and include the link below.

No.

Before submitting this PR, please make sure you have:

  • run ./gradlew checkAll and confirmed all checks still pass OR confirm CircleCI build passes and run ./gradlew connectedDebugAndroidTest locally.
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.
  • verified that any new UI elements use theme colors. UI Components Style guidelines

For example, during an orientation change.
@lognaturel lognaturel added the high priority Should be looked at before other PRs/issues label Apr 2, 2019
Copy link
Contributor

@zestyping zestyping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I was able to take a moment to examine how this crash happened. getActivity() returns null when a Fragment has yet to be attached. So if the GoogleMapFragment is constructed and a location update arrives in the tiny period between construction and being attached to the activity, the activity can be null during updateLocationIndicator().

So I fully agree with your assessment that the null check in onLocationReady resolves the crash in #2979, and the null check in createMarker is probably not necessary but doesn't hurt.

@mmarciniak90
Copy link
Contributor

Tested with success

Verified on Android: 4.2, 4.4, 5.1, 6.0, 7.0, 8.1

Verified cases:

  • rotating
  • all Geo Widgets in All widgets form
  • Do not keep activities turned on/off

@opendatakit-bot unlabel "needs testing"
@opendatakit-bot label "behavior verified"

@grzesiek2010 grzesiek2010 merged commit 8748be4 into getodk:master Apr 2, 2019
@grzesiek2010 grzesiek2010 added this to the v1.21 milestone Apr 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
behavior verified high priority Should be looked at before other PRs/issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

App crashes if the user opens some GeoWidget with Google Map and immediately changes device orientation
5 participants