-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(nearby): Prevent crash in offline search caused by null map boundaries #6579
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
base: main
Are you sure you want to change the base?
fix(nearby): Prevent crash in offline search caused by null map boundaries #6579
Conversation
|
Note: I am getting this crash on app start frequently, but this happens in other branches too: |
nicolas-raoul
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can reproduce the crash in main but not on this branch, great! :-)
About the code:
Boundaries being null sounds like there was an issue higher in the callstack. Would you mind trying to identify what led to boundaries being null? Probably that's because a network call failed somewhere? If yes, better exit gracefully there, rather than down the stream.
@nicolas-raoul Thanks for verifying the fix! I agree that tracing the null boundaries upstream is the more robust approach. I've investigated the map boundaries further by inspecting the NearbyParentFragment.kt. The reason they appeared 'null' (or uninitialized) was twofold:
The most logical upstream point to handle the failure of the map to initialize is right before we consume these properties in the This ensures that the application flow is immediately stopped and doesn't proceed with a search if the necessary map dependencies (the corner coordinates) haven't been successfully initialized by the View layer, which is the earliest point of control we have over those specific variables. I believe the neww commit addressess the root of the control flow issue by validating map readiness before continuing the network-independent search logic. llet me know if you would prefer to see error handling added directly within the Fragment's |
|
(tested: bug does not reproduce with these commits either)
Nearby does not crash when I go (while offline) from home activity to Nearby activity. Upon choosing a picture, ideally the Nearby activity should not be used any further. Once a picture has been chosen, we just show the upload wizard, and do not need to call |
|
@nicolas-raoul Sorry about this! I’m in the middle of my end-sem exams right now, so I couldn’t find time to work on the issue. I’ll continue to work on thiss after the 27th 🙂 |
|
Good luck with your exams! 🙂 |
|
Hi @nicolas-raoul, i have updated the fix to address the root cause as suggested. instead of catching nulls at the data layer, i implemented a 'flow lock' using an isInternalUploadInProgress flag in the NearbyController. This flag is set by the ContributionController the moment an image is selected and checked by the NearbyParentFragmentPresenter at the beginning of updateMapAndList. this ensures that returning from the camera gracefully exits the refresh logic before any map coordinates are requested, preventing unnecessary calls during the transition to the upload wizard. |
|
✅ Generated APK variants! |
Description
Fixes #6469
What changes did you make and why?
This pull request addressses the critical application crash (
NullPointerException) that was triggered when users attempted an action requiring location dataa (like taking a picture from the "Nearby" tab) while the device was offline or had a severely flaky internet connection.The root cause isthat the
NearbyParentFragmentPresenterattempted to fetch map boundary coordinates (screenBottomLeftandscreenTopRight) from the map view. When offline, these coordinates areoften uninitialized and returned null. This null value was then passed down to the Java data source method, leading to a crash when code attempted to call.getLatitude()on the null object.The solution ensures the robust handling of the offline/uninitialized state:
screenBottomLeftandscreenTopRightwithin thehandleMapScrolledoffline logic. If the map boundaries are null, the local place search job is now gracefully exited, preventing the null values from ever reaching the data layer.fetchPlacesmethod. If either map boundary input is null, it now returns an empty list immediately instead of risking aNullPointerExceptionon the map boundary processing logicc.Tests performed (required)
Tested ProDebug on Redmi Note 13 Pro 5g with API level 35.
Screenshots (for UI changes only)
N/A (This is a code stability fix, not a UI change)