Add null guard for mControllers in no-location dialog handler #1526
Add null guard for mControllers in no-location dialog handler #1526amanjn38 wants to merge 2 commits into
Conversation
…h Google and MapLibre map fragment
aaronbrethorst
left a comment
There was a problem hiding this comment.
Aman, good catch on the mControllers null guard — dialog callbacks run asynchronously, so it's entirely possible for the fragment to be in a partially-initialized state when the user taps "No" on the location dialog. One issue to fix before this can merge.
Critical Issues (1 found)
1. Missing mMapFragment null check in Google variant
BaseMapFragment.java:1362 — The new null guard checks mMapFragment.mControllers != null, but doesn't first check whether mMapFragment itself is null. If mMapFragment is null, this line will throw the same NullPointerException the PR aims to prevent.
The other dialog handlers in the same class already follow the correct pattern (lines 1315 and 1323):
if (mMapFragment != null && mMapFragment.isAdded()) {And the MapLibre variant in this PR correctly chains all three checks:
if (mapFragment != null && mapFragment.isAdded()
&& mapFragment.mControllers != null) {The Google variant should match. Replace line 1362:
if (mMapFragment != null && mMapFragment.isAdded()
&& mMapFragment.mControllers != null) {Important Issues (0 found)
None.
Suggestions (0 found)
None.
Strengths
- The MapLibre variant correctly chains all three safety checks (
!= null,isAdded(),mControllers != null) - The fix is minimal and well-scoped to the crash site
Recommended Action
Request changes. Add the mMapFragment != null && mMapFragment.isAdded() guard in the Google variant to match the MapLibre variant and the existing patterns in the same class.
|
Thanks for the review! Fixed — updated line 1362 to chain all three checks (mMapFragment != null && mMapFragment.isAdded() && mMapFragment.mControllers != null) to match both the MapLibre variant and the existing dialog handlers at lines 1315/1323. |
Add null guard for mControllers in no-location dialog handler for both Google and MapLibre map fragment
Fixes #1523
Please make sure these boxes are checked before submitting your pull request - thanks!
Apply the
AndroidStyle.xmlstyle template to your code in Android Studio.Run the unit tests with
gradlew connectedObaGoogleDebugAndroidTestto make sure you didn't break anythingIf you have multiple commits please combine them into one commit by squashing them for the initial submission of the pull request. When addressing comments on a pull request, please push a new commit per comment when possible (reviewers will squash and merge using GitHub merge tool)