Skip to content

Crash when testing reroute example #351

Closed

Description

@Guardiola31337

Platform: Android 6.0 (Nexus 5)
Mapbox Navigation version: master branch

Steps to trigger behavior

  1. Open test app
  2. Go to Reroute example
  3. Click outside the route
  4. Start rerouting
  5. Click back button at the top
  6. 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

(int) sessionState.routeProgressBeforeReroute().distanceTraveled(),
(int) sessionState.routeProgressBeforeReroute().distanceRemaining(),
(int) sessionState.routeProgressBeforeReroute().durationRemaining(),

may produce NullPointerException.

cc @cammace @ericrwolfe @zugaldia @electrostat

Activity

  1. sparkle-sparkle commented on Oct 11, 2017

    @sparkle-sparkle

    I'll have a look at it and see if I can figure out where the null is coming from.

  2. Guardiola31337 commented on Oct 11, 2017

    @Guardiola31337
    ContributorAuthor

    @sparkle-sparkle awesome! Go for it 💪 and let us know if you have any questions! Thanks 🙏

  3. sparkle-sparkle commented on Oct 11, 2017

    @sparkle-sparkle

    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:

    10-11 18:08:51.994 2939-2939/com.mapbox.services.android.navigation.testapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                                  Process: com.mapbox.services.android.navigation.testapp, PID: 2939
                                                                                                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mapbox.services.android.navigation.testapp/com.mapbox.services.android.navigation.testapp.activity.RerouteActivity}: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class com.mapbox.mapboxsdk.maps.MapView
                                                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                                      at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                                      at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                                      at android.os.Looper.loop(Looper.java:164)
                                                                                                      at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                                                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                                                   Caused by: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class com.mapbox.mapboxsdk.maps.MapView
                                                                                                   Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class com.mapbox.mapboxsdk.maps.MapView
                                                                                                   Caused by: java.lang.reflect.InvocationTargetException
                                                                                                      at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                                                                      at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
                                                                                                      at android.view.LayoutInflater.createView(LayoutInflater.java:647)
                                                                                                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
                                                                                                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
                                                                                                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
                                                                                                      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
                                                                                                      at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                                                                                                      at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                                                                                                      at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                                                                                                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                                                                                                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                                                                      at com.mapbox.services.android.navigation.testapp.activity.RerouteActivity.onCreate(RerouteActivity.java:65)
                                                                                                      at android.app.Activity.performCreate(Activity.java:6975)
                                                                                                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                                      at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                                      at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                                      at android.os.Looper.loop(Looper.java:164)
                                                                                                      at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                                                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                                                   Caused by: com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException: 
                                                                                                  Using MapView requires setting a valid access token. Use Mapbox.getInstance(Context context, String accessToken) to provide one. 
                                                                                                  Please see https://www.mapbox.com/help/create-api-access-token/ to learn how to create one.
                                                                                                  More information in this guide https://www.mapbox.com/help/first-steps-android-sdk/#access-tokens.
                                                                                                      at com.mapbox.mapboxsdk.Mapbox.validateAccessToken(Mapbox.java:101)
                                                                                                      at com.mapbox.mapboxsdk.Mapbox.getAccessToken(Mapbox.java:79)
                                                                                                      at com.mapbox.mapboxsdk.storage.FileSource.<init>(FileSource.java:124)
                                                                                                      at com.mapbox.mapboxsdk.storage.FileSource.getInstance(FileSource.java:51)
                                                                                                      at com.mapbox.mapboxsdk.maps.NativeMapView.<init>(NativeMapView.java:81)
                                                                                                      at com.mapbox.mapboxsdk.maps.MapView.initialise(MapView.java:115)
    10-11 18:08:51.994 2939-2939/com.mapbox.services.android.navigation.testapp E/AndroidRuntime:     at com.mapbox.mapboxsdk.maps.MapView.<init>(MapView.java:81)
                                                                                                      	... 25 more
    
  4. zugaldia commented on Oct 11, 2017

    @zugaldia
    Member

    @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.

  5. sparkle-sparkle commented on Oct 11, 2017

    @sparkle-sparkle

    Thank you! That fixed it. I couldn't find where I needed to add my API token.

  6. sparkle-sparkle commented on Oct 11, 2017

    @sparkle-sparkle

    Steps taken:

    1. start the app
    2. choose Reroute
    3. click somewhere on the map (outside drawn route)

    result:
    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?

  7. Guardiola31337 commented on Oct 11, 2017

    @Guardiola31337
    ContributorAuthor

    Hey @sparkle-sparkle thanks for reporting your findings.

    As indicated in OP you should:

    1. Click back button at the top

    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:

    (int) sessionState.routeProgressBeforeReroute().distanceTraveled(),
    (int) sessionState.routeProgressBeforeReroute().distanceRemaining(),
    (int) sessionState.routeProgressBeforeReroute().durationRemaining(),

    Adding checks for those cases should do the trick.
    Let us know if you have any other follow up questions. Thanks!

  8. sparkle-sparkle commented on Oct 13, 2017

    @sparkle-sparkle

    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...

  9. Grsmto commented on Oct 20, 2017

    @Grsmto

    Is anyone working on this? For reference this is a duplicate of #395.

  10. sparkle-sparkle commented on Oct 20, 2017

    @sparkle-sparkle

    I cannot reproduce the NPE. I am currently not working on it anymore.

  11. Guardiola31337 commented on Oct 20, 2017

    @Guardiola31337
    ContributorAuthor

    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.

  12. added this to the v0.7.0 milestone on Oct 20, 2017
  13. palto-ccadoret commented on Oct 23, 2017

    @palto-ccadoret

    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

  14. Grsmto commented on Oct 24, 2017

    @Grsmto

    Hey sorry, I didn't figure out how to fix this so I'm not about to submit a PR :/

  15. palto-blubek commented on Oct 31, 2017

    @palto-blubek

    Hey guys, I've also experienced the same NPE.

    I notice that a null check is done on routeProgress before calling cancelEvent here:
    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 routeProgress can be null at this point.

    However, on the line right before this, a call to sendRerouteEvent is made, not inside the null check. And sendRerouteEvent calls NavigationMetricsWrapper.rerouteEvent(sessionState, routeProgress, sessionState.lastRerouteLocation()) which uses routeProgress and assumes it is not null.

    A crash is therefore inevitable.

    I would be grateful if someone from Mapbox could confirm this :)

  16. danesfeder commented on Oct 31, 2017

    @danesfeder
    Contributor

    Thanks for the feedback everyone - we are working to resolve the issues being found in NavigationMetricsWrapper this 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!

  17. cammace commented on Nov 7, 2017

    @cammace

    With #457, this issue should be resolved now, closing.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions