Skip to content

Add null guard for mControllers in no-location dialog handler #1526

Open
amanjn38 wants to merge 2 commits into
OneBusAway:mainfrom
amanjn38:fix/maplibre-dialog-null-guard
Open

Add null guard for mControllers in no-location dialog handler #1526
amanjn38 wants to merge 2 commits into
OneBusAway:mainfrom
amanjn38:fix/maplibre-dialog-null-guard

Conversation

@amanjn38

@amanjn38 amanjn38 commented Mar 15, 2026

Copy link
Copy Markdown
Contributor

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.xml style template to your code in Android Studio.

  • Run the unit tests with gradlew connectedObaGoogleDebugAndroidTest to make sure you didn't break anything

  • If 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)

@aaronbrethorst aaronbrethorst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@amanjn38

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add null guard for mControllers in MapLibreMapFragment dialog handler

2 participants