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

Fix NPE when PlatformUtil.getOsmandRegions() is not ready #21374

Merged
merged 1 commit into from
Nov 19, 2024

Conversation

RZR-UA
Copy link
Contributor

@RZR-UA RZR-UA commented Nov 18, 2024

Fixes multiple NPE (was displayed as a toast) when Navigation started immediately after OsmAnd start (previous navigation and/or quick navigation to any point is the action to reproduce).

The problem might happen when PlatformUtil.getOsmandRegions() is still not ready, searchRoute() starts and MissingMapsCalculator requires non-null regions.

On slow devices, the bug might happen even in 5-10 seconds after OsmAnd is loaded and UI is ready.

Now the frightening NPE message in the toast changed to "Calculating route…" from strings.xml

PS. Additionally, the same issue in NavigationSession should be fixed by this request, because if (app.getRegions() != null) seems as incorrect way to validate regions.

14:43:41.270  E  RouteProvider Runtime error: Attempt to invoke virtual method 'net.osmand.map.WorldRegion net.osmand.map.OsmandRegions.getRegionDataByDownloadName(java.lang.String)' on a null object reference {pool-4-thread-1}
                 java.lang.NullPointerException: Attempt to invoke virtual method 'net.osmand.map.WorldRegion net.osmand.map.OsmandRegions.getRegionDataByDownloadName(java.lang.String)' on a null object reference
                   at net.osmand.router.MissingMapsCalculator.checkIfThereAreMissingMaps(MissingMapsCalculator.java:75)
                   at net.osmand.router.RoutePlannerFrontEnd.searchRoute(RoutePlannerFrontEnd.java:400)
                   at net.osmand.router.RoutePlannerFrontEnd.searchRoute(RoutePlannerFrontEnd.java:220)
                   at net.osmand.plus.routing.RouteProvider.calcOfflineRouteImpl(RouteProvider.java:901)
                   at net.osmand.plus.routing.RouteProvider.findVectorMapsRoute(RouteProvider.java:822)
                   at net.osmand.plus.routing.RouteProvider.calculateRouteImpl(RouteProvider.java:141)
                   at net.osmand.plus.routing.RouteRecalculationHelper$RouteRecalculationTask.run(RouteRecalculationHelper.java:373)
                   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:459)
                   at java.util.concurrent.FutureTask.run(FutureTask.java:266)
                   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
                   at java.lang.Thread.run(Thread.java:764)
14:43:41.660  E  RouteProvider Runtime error: Attempt to invoke virtual method 'net.osmand.map.WorldRegion net.osmand.map.OsmandRegions.getRegionDataByDownloadName(java.lang.String)' on a null object reference {main}
                 java.lang.NullPointerException: Attempt to invoke virtual method 'net.osmand.map.WorldRegion net.osmand.map.OsmandRegions.getRegionDataByDownloadName(java.lang.String)' on a null object reference
                   at net.osmand.router.MissingMapsCalculator.checkIfThereAreMissingMaps(MissingMapsCalculator.java:75)
                   at net.osmand.router.RoutePlannerFrontEnd.searchRoute(RoutePlannerFrontEnd.java:400)
                   at net.osmand.plus.routing.RouteProvider.calcOfflineRouteImpl(RouteProvider.java:890)
                   at net.osmand.plus.routing.RouteProvider.findVectorMapsRoute(RouteProvider.java:822)
                   at net.osmand.plus.routing.RouteProvider.calculateRouteImpl(RouteProvider.java:141)
                   at net.osmand.plus.routing.RouteRecalculationHelper$RouteRecalculationTask.run(RouteRecalculationHelper.java:373)

@RZR-UA RZR-UA requested a review from alex-osm November 18, 2024 18:27
@RZR-UA RZR-UA marked this pull request as ready for review November 18, 2024 18:27
@RZR-UA
Copy link
Contributor Author

RZR-UA commented Nov 18, 2024

@RZR-UA RZR-UA force-pushed the rzr-npe-regions branch 4 times, most recently from 7fc188b to fc11bb0 Compare November 19, 2024 07:07
@alex-osm alex-osm merged commit b13205d into master Nov 19, 2024
3 checks passed
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.

3 participants