Skip to content

Commit 0934b06

Browse files
authored
Fix possible IndexOutOfBoundsException exception (#1013)
Check if list is empty before getting its items. Also add an annotation to indicate that steps parameter should be greater than 0.
1 parent 5c65967 commit 0934b06

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

services-turf/src/main/java/com/mapbox/turf/TurfTransformation.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mapbox.turf;
22

3+
import android.support.annotation.IntRange;
34
import android.support.annotation.NonNull;
45

56
import com.mapbox.geojson.Polygon;
@@ -62,14 +63,16 @@ public static Polygon circle(@NonNull Point center, double radius,
6263
* @return a {@link Polygon} which represents the newly created circle
6364
* @since 3.0.0
6465
*/
65-
public static Polygon circle(@NonNull Point center, double radius, int steps,
66+
public static Polygon circle(@NonNull Point center, double radius, @IntRange(from = 1) int steps,
6667
@TurfConstants.TurfUnitCriteria String units) {
6768
List<Point> coordinates = new ArrayList<>();
6869
for (int i = 0; i < steps; i++) {
6970
coordinates.add(TurfMeasurement.destination(center, radius, i * 360d / steps, units));
7071
}
71-
coordinates.add(coordinates.get(0));
7272

73+
if (coordinates.size() > 0) {
74+
coordinates.add(coordinates.get(0));
75+
}
7376
List<List<Point>> coordinate = new ArrayList<>();
7477
coordinate.add(coordinates);
7578
return Polygon.fromLngLats(coordinate);

0 commit comments

Comments
 (0)