mapbox / mapbox/mapbox-navigation-android
MapboxDirections returns route with no steps causing MapRouteLine crash
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 651
- Forks
- 321
- PR merge metrics
- No merged PRs in 30d
Description
I'm migrating from Navigation SDK 0.42.3 to 1.5.1 and I'm getting problems with requesting a route. I switched from NavigationRoute class to MapboxDirections class as NavigationRoute was removed. You can find more details on implementation at the end of issue description.
### Steps to trigger behavior
1. Request route via MapboxDirections.builder()
2. In onResponse() callback provided in enqueueCall() method of MapboxDirections.builder() pass the route to NavigationMapRoute.addRoute()
3. Observe the crash and check logs
Here are route details:
```
DirectionsRoute{routeIndex=0, distance=3547.207, duration=389.967, durationTypical=null, geometry=yfyipAzvsw}Cp@bJun@`{@glA}e@o~Cli@gXig_@oKcmBmjCr@}oJ{d@f@|u@faBcRfRd[pCfvB`O]LlMe_@f@, weight=1754.069, weightName=auto, legs=[RouteLeg{distance=3547.207, duration=389.967, durationTypical=null, summary=Featherstone Road, Chrysler Drive, admins=[Admin{countryCode=US, countryCodeAlpha3=USA}], steps=[], incidents=null, annotation=null}], routeOptions=RouteOptions{baseUrl=https://api.mapbox.com, user=mapbox, profile=driving, coordinates=[Point{type=Point, bbox=null, coordinates=[-83.24126434326172, 42.64449691772461]}, Point{type=Point, bbox=null, coordinates=[-83.22702026367188, 42.65614318847656]}], alternatives=null, language=null, radiuses=null, bearings=null, continueStraight=null, roundaboutExits=null, geometries=polyline6, overview=null, steps=null, annotations=null, exclude=null, voiceInstructions=null, bannerInstructions=null, voiceUnits=imperial, accessToken=, approaches=null, waypointIndices=null, waypointNames=null, waypointTargets=null, walkingOptions=null}, voiceLanguage=null}
```
### Expected behavior
Route from MapboxDirections should be displayed in NavigationMapRoute without other manipulation or if it was not possible to provide a route there should be some error handling mechanism which don't cause crash of Map SDK.
It should work as before, i.e. in the old SDK version request created for the same origin and destination with `NavigationRoute` returns a route with one leg containing 12 steps.
### Actual behavior
```
1970-01-01 01:02:22.267 7607-7607/ E/AndroidRuntime: FATAL EXCEPTION: main
Process: de.conti.r2d2.mapboxnavigation, PID: 7607
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.get(ArrayList.java:437)
at com.mapbox.navigation.ui.route.MapRouteLine$MapRouteLineSupport.buildWayPointFeatureFromLeg(MapRouteLine.kt:1607)
at com.mapbox.navigation.ui.route.MapRouteLine$MapRouteLineSupport.buildWayPointFeatureCollection(MapRouteLine.kt:1584)
at com.mapbox.navigation.ui.route.MapRouteLine.drawWayPoints(MapRouteLine.kt:888)
at com.mapbox.navigation.ui.route.MapRouteLine.reinitializeWithRoutes(MapRouteLine.kt:591)
at com.mapbox.navigation.ui.route.MapRouteLine.draw(MapRouteLine.kt:554)
at com.mapbox.navigation.ui.route.NavigationMapRoute.addRoutes(NavigationMapRoute.java:221)
at com.mapbox.navigation.ui.route.NavigationMapRoute.addRoute(NavigationMapRoute.java:200)
at .RouteViewModel$2.onResponse(RouteViewModel.java:304)
at com.mapbox.api.directions.v5.MapboxDirections$1.onResponse(MapboxDirections.java:186)
at retrofit2.DefaultCallAdapterFactory$ExecutorCallbackCall$1.lambda$onResponse$0$DefaultCallAdapterFactory$ExecutorCallbackCall$1(DefaultCallAdapterFactory.java:81)
at retrofit2.-$$Lambda$DefaultCallAdapterFactory$ExecutorCallbackCall$1$3wC8FyV4pyjrzrYL5U0mlYiviZw.run(Unknown Source:6)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
1970-01-01 01:02:22.294 7607-7607/ I/Process: Sending signal. PID: 7607 SIG: 9
```
### More details on implementation
Here is the diff of changes I made when migrating from Navigation SDK 0.42.3 to 1.5.1.
```diff
@@ -249,20 +250,22 @@ public class RouteViewModel extends AndroidViewModel {
/**
* Send route request to Mapbox's server
*/
- public void getRoute(MapView mapView, MapboxMap mapboxMap) {
+ public void getRoute(MapView mapView, MapboxMap mapboxMap, LifecycleOwner lifecycleOwner) {
try {
if (startPoint.getValue() != null && destinationPoint.getValue() != null) {
- NavigationRoute.builder(getApplicationContext())
+ MapboxDirections.builder()
.accessToken(getApplicationContext().getString(R.string.mapbox_token))
.origin(startPoint.getValue())
.destination(destinationPoint.getValue())
.profile(DirectionsCriteria.PROFILE_DRIVING)
.voiceUnits(DirectionsCriteria.IMPERIAL)
.build()
- .getRoute(new Callback() {
+ .enqueueCall(new Callback() {
@Override
public void onResponse(Call call, Response response) {
// You can get the generic HTTP info about the response
@@ -283,7 +286,10 @@ public class RouteViewModel extends AndroidViewModel {
// Draw the route on the map
if (navigationMapRoute == null) {
- navigationMapRoute = new NavigationMapRoute(null, mapView, mapboxMap, R.style.NavigationMapRoute);
+ navigationMapRoute = new NavigationMapRoute.Builder(
+ mapView, mapboxMap, lifecycleOwner)
+ .withStyle(R.style.NavigationMapRoute)
+ .build();
}
navigationMapRoute.addRoute(currentRoute.getValue()); // << this call is in stacktrace (RouteViewModel.java:304)
showProgressBar.setValue(false);
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the MapRouteLine.kt stack-trace path, then inspect NavigationMapRoute.java and the RouteViewModel.java call to addRoute() shown in the report. Compare how MapboxDirections.builder() constructs the route with the older NavigationRoute request. Done means a route with an empty steps list no longer crashes NavigationMapRoute and the reported route is displayed or handled without an SDK crash.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java, kotlin
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100