Repository navigation
Closed
Description
Platform: Android 6.0 (Nexus 5)
Mapbox Navigation version: master branch
Steps to trigger behavior
- Open test app
- Go to
Rerouteexample - Click outside the route
- Start rerouting
- Click back button at the top
- App crashes
logcat
10-11 10:21:02.836 15054-15054/com.mapbox.services.android.navigation.testapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mapbox.services.android.navigation.testapp, PID: 15054
java.lang.NullPointerException: Attempt to invoke virtual method 'double com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress.distanceTraveled()' on a null object reference
at com.mapbox.services.android.navigation.v5.navigation.NavigationMetricsWrapper.rerouteEvent(NavigationMetricsWrapper.java:110)
at com.mapbox.services.android.navigation.v5.navigation.NavigationService$1.run(NavigationService.java:282)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Noting here that
Lines 110 to 112 in 0fa13a0
| (int) sessionState.routeProgressBeforeReroute().distanceTraveled(), | |
| (int) sessionState.routeProgressBeforeReroute().distanceRemaining(), | |
| (int) sessionState.routeProgressBeforeReroute().durationRemaining(), |
may produce
NullPointerException.
Activity
sparkle-sparkle commentedon Oct 11, 2017
I'll have a look at it and see if I can figure out where the null is coming from.
Guardiola31337 commentedon Oct 11, 2017
@sparkle-sparkle awesome! Go for it 💪 and let us know if you have any questions! Thanks 🙏
sparkle-sparkle commentedon Oct 11, 2017
I cannot start the Rerouting at all. I have the application up and running in a virtual Android device (API level 26, O). When I click/press on 'Reroute' the app crashes. Am I missing something in my setup? I use Android Studio.
In LogCat I see the following stacktrace:
zugaldia commentedon Oct 11, 2017
@sparkle-sparkle Thanks for digging into this one. Looks like you need to set up your Mapbox access token, look for a developer config file in the
values.folder. You can get your (free) token from mapbox.com.sparkle-sparkle commentedon Oct 11, 2017
Thank you! That fixed it. I couldn't find where I needed to add my API token.
sparkle-sparkle commentedon Oct 11, 2017
Steps taken:
Rerouteresult:
After a delay I can see that de route is recalculated/redrawn. I do not see any NullPointerExceptions occurring.
I am trying to figure out where the different outcomes are coming from.
Are the described steps exactly as you executed them when the NPE occurred? Is there a difference perhaps in setup? Something else?
Guardiola31337 commentedon Oct 11, 2017
Hey @sparkle-sparkle thanks for reporting your findings.
As indicated in OP you should:
and then sometimes the app crashes. The reason of this randomness it's because events are sent asynchronously and most of the times the resources are cleaned up properly but not always. Try it a couple of times and you'll hit the crash. BTW, the issue is that we're not checking nullability here:
mapbox-navigation-android/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationMetricsWrapper.java
Lines 110 to 112 in 0fa13a0
Adding checks for those cases should do the trick.
Let us know if you have any other follow up questions. Thanks!
sparkle-sparkle commentedon Oct 13, 2017
I have rerouted, following the previously mentioned steps and clicked the back button at the top of the screen and so far I haven't seen a NPE...
Grsmto commentedon Oct 20, 2017
Is anyone working on this? For reference this is a duplicate of #395.
sparkle-sparkle commentedon Oct 20, 2017
I cannot reproduce the NPE. I am currently not working on it anymore.
Guardiola31337 commentedon Oct 20, 2017
As @palto-ccadoret reported in #395 NPE could also happen in
sessionState.routeProgressBeforeReroute().@sparkle-sparkle
Thanks for trying to reproduce OP.
@Grsmto
Thanks for the heads up and if you want to tackle it, go for it because @sparkle-sparkle is not working on it.
Let us know if you have any follow up questions. Happy to help.
palto-ccadoret commentedon Oct 23, 2017
Thanks @Guardiola31337
Another stacktrace :
com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress.distanceTraveled()' on a null object reference at android.app.ActivityThread.handleStopService(ActivityThread.java:3344) at android.app.ActivityThread.-wrap27(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1570) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'double com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress.distanceTraveled()' on a null object reference at com.mapbox.services.android.navigation.v5.navigation.NavigationMetricsWrapper.rerouteEvent(NavigationMetricsWrapper.java:110) at com.mapbox.services.android.navigation.v5.navigation.NavigationService$1.run(NavigationService.java:282) at com.mapbox.services.android.navigation.v5.navigation.NavigationService.onDestroy(NavigationService.java:96) at android.app.ActivityThread.handleStopService(ActivityThread.java:3327) at android.app.ActivityThread.-wrap27(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1570) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)I use the version 0.6.2 of mapbox navigation.
@sparkle-sparkle, don't know why but a reroute occurs when ending the navigation.
If you start twice a navigation, a reroute seems to occur
and the route progress seems to be constucted asynchronously
Grsmto commentedon Oct 24, 2017
Hey sorry, I didn't figure out how to fix this so I'm not about to submit a PR :/
palto-blubek commentedon Oct 31, 2017
Hey guys, I've also experienced the same NPE.
I notice that a null check is done on
routeProgressbefore callingcancelEventhere:https://github.com/mapbox/mapbox-navigation-android/blob/v0.6.3/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationService.java#L105
This means it is expected that
routeProgresscan be null at this point.However, on the line right before this, a call to
sendRerouteEventis made, not inside the null check. AndsendRerouteEventcallsNavigationMetricsWrapper.rerouteEvent(sessionState, routeProgress, sessionState.lastRerouteLocation())which usesrouteProgressand assumes it is not null.A crash is therefore inevitable.
I would be grateful if someone from Mapbox could confirm this :)
danesfeder commentedon Oct 31, 2017
Thanks for the feedback everyone - we are working to resolve the issues being found in
NavigationMetricsWrapperthis week for the next release. Keep an eye on the PRs moving and we will update this ticket when the fixes land. Thank you for your patience!cammace commentedon Nov 7, 2017
With #457, this issue should be resolved now, closing.