Skip to content

RouteOptions parsing issuse #1120

@LukasPaczos

Description

@LukasPaczos

I was working with changes from #1118 today and noticed 2 issues so far:

I run into this NPE:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.mapbox.geojson.Point.coordinates()' on a null object reference
    at com.mapbox.geojson.BaseCoordinatesTypeAdapter.writePoint(BaseCoordinatesTypeAdapter.java:29)
    at com.mapbox.geojson.PointAsCoordinatesTypeAdapter.write(PointAsCoordinatesTypeAdapter.java:21)
    at com.mapbox.geojson.PointAsCoordinatesTypeAdapter.write(PointAsCoordinatesTypeAdapter.java:16)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:97)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:61)
    at com.mapbox.api.directions.v5.models.AutoValue_RouteOptions$GsonTypeAdapter.write(AutoValue_RouteOptions.java:300)
    at com.mapbox.api.directions.v5.models.AutoValue_RouteOptions$GsonTypeAdapter.write(AutoValue_RouteOptions.java:41)
    at com.google.gson.Gson.toJson(Gson.java:704)
    at com.google.gson.Gson.toJson(Gson.java:683)
    at com.google.gson.Gson.toJson(Gson.java:638)
    at com.google.gson.Gson.toJson(Gson.java:618)
    at com.mapbox.api.directions.v5.models.DirectionsJsonObject.toJson(DirectionsJsonObject.java:30)

when initially provided waypoint_targets were ";lng,lat". That's because the serialization of Point doesn't expect nulls in BaseCoordinatesTypeAdapter.

Which brings us to issue number 2 - the newly created list of arguments do not accept nulls. An example can be the above crash, but also a way we need to provide other fields like bearingsList:

routeOptionsBuilder.bearingsList(listOf(listOf(angle, BEARING_TOLERANCE), listOf(null, null)))

We should instead be able to do:

routeOptionsBuilder.bearingsList(listOf(listOf(angle, BEARING_TOLERANCE), null))

but this will crash at bearings.size():

public Builder bearings(@NonNull List<List<Double>> bearings) {
List<List<Double>> newBearings = new ArrayList<>();
for (List<Double> bearing : bearings) {
if (bearing.size() != 2) {
throw new ServicesException("Bearing size should be 2.");
}

which will throw and prevent us from making a request.

We'll need to iteratively iron out those conversion issues and cover them with tests, especially the JSON conversion.

@korshaknn would you be able to look into this?

/cc @mapbox/navigation-android if you see any other incompatibilities

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions