Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Avoid IndexOutOfBoundsException when destroying map object #9789

Merged
merged 1 commit into from
Aug 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public List<Marker> addBy(@NonNull List<? extends BaseMarkerOptions> markerOptio
mapboxMap) {
int count = markerOptionsList.size();
List<Marker> markers = new ArrayList<>(count);
if (count > 0) {
if (nativeMapView != null && count > 0) {
BaseMarkerOptions markerOptions;
Marker marker;
for (int i = 0; i < count; i++) {
Expand All @@ -63,26 +63,13 @@ public List<Marker> addBy(@NonNull List<? extends BaseMarkerOptions> markerOptio
}

if (markers.size() > 0) {
long[] ids = null;
if (nativeMapView != null) {
ids = nativeMapView.addMarkers(markers);
long[] ids = nativeMapView.addMarkers(markers);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the if (nativeMapView != null) check was lost during the refactor. Wouldn't we want to reintroduce it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with the other two cases below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed with 7335566

for (int i = 0; i < ids.length; i++) {
Marker createdMarker = markers.get(i);
createdMarker.setMapboxMap(mapboxMap);
createdMarker.setId(ids[i]);
annotations.put(ids[i], createdMarker);
}

long id = 0;
Marker m;
for (int i = 0; i < markers.size(); i++) {
m = markers.get(i);
m.setMapboxMap(mapboxMap);
if (ids != null) {
id = ids[i];
} else {
// unit test
id++;
}
m.setId(id);
annotations.put(id, m);
}

}
}
return markers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,20 @@ public List<Polygon> addBy(@NonNull List<PolygonOptions> polygonOptionsList, @No

Polygon polygon;
List<Polygon> polygons = new ArrayList<>(count);
if (count > 0) {
if (nativeMapView != null && count > 0) {
for (PolygonOptions polygonOptions : polygonOptionsList) {
polygon = polygonOptions.getPolygon();
if (!polygon.getPoints().isEmpty()) {
polygons.add(polygon);
}
}

long[] ids = null;
if (nativeMapView != null) {
ids = nativeMapView.addPolygons(polygons);
}

long id = 0;
for (int i = 0; i < polygons.size(); i++) {
long[] ids = nativeMapView.addPolygons(polygons);
for (int i = 0; i < ids.length; i++) {
polygon = polygons.get(i);
polygon.setMapboxMap(mapboxMap);
if (ids != null) {
id = ids[i];
} else {
// unit test
id++;
}
polygon.setId(id);
annotations.put(id, polygon);
polygon.setId(ids[i]);
annotations.put(ids[i], polygon);
}
}
return polygons;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,20 @@ public List<Polyline> addBy(@NonNull List<PolylineOptions> polylineOptionsList,
int count = polylineOptionsList.size();
Polyline polyline;
List<Polyline> polylines = new ArrayList<>(count);

if (count > 0) {
if (nativeMapView != null && count > 0) {
for (PolylineOptions options : polylineOptionsList) {
polyline = options.getPolyline();
if (!polyline.getPoints().isEmpty()) {
polylines.add(polyline);
}
}

long[] ids = null;
if (nativeMapView != null) {
ids = nativeMapView.addPolylines(polylines);
}

long id = 0;
Polyline p;

for (int i = 0; i < polylines.size(); i++) {
p = polylines.get(i);
p.setMapboxMap(mapboxMap);
if (ids != null) {
id = ids[i];
} else {
// unit test
id++;
}
p.setId(id);
annotations.put(id, p);
long[] ids = nativeMapView.addPolylines(polylines);
for (int i = 0; i < ids.length; i++) {
Polyline polylineCreated = polylines.get(i);
polylineCreated.setMapboxMap(mapboxMap);
polylineCreated.setId(ids[i]);
annotations.put(ids[i], polylineCreated);
}
}
return polylines;
Expand Down