Skip to content

Commit a04b9d5

Browse files
authored
coordinates() should have @NotNull annotation in Geometry implementations (#882)
1 parent 124565f commit a04b9d5

9 files changed

Lines changed: 63 additions & 4 deletions

File tree

services-geojson/src/main/java/com/mapbox/geojson/Feature.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ public static Feature fromGeometry(@Nullable Geometry geometry, @Nullable JsonOb
165165
*/
166166
public static Feature fromGeometry(@Nullable Geometry geometry, @NonNull JsonObject properties,
167167
@Nullable String id, @Nullable BoundingBox bbox) {
168-
return new AutoValue_Feature(TYPE, bbox, id, geometry, properties);
168+
return new AutoValue_Feature(TYPE, bbox, id, geometry,
169+
properties == null ? new JsonObject() : properties);
169170
}
170171

171172
/**

services-geojson/src/main/java/com/mapbox/geojson/MultiPoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static MultiPoint fromLngLats(@NonNull double[][] coordinates) {
130130
* @return a list of points
131131
* @since 3.0.0
132132
*/
133-
@Nullable
133+
@NonNull
134134
@Override
135135
public abstract List<Point> coordinates();
136136

services-geojson/src/main/java/com/mapbox/geojson/Polygon.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public List<LineString> inner() {
323323
* @return a list of points
324324
* @since 3.0.0
325325
*/
326-
@Nullable
326+
@NonNull
327327
@Override
328328
public abstract List<List<Point>> coordinates();
329329

services-geojson/src/test/java/com/mapbox/geojson/LineStringTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,10 @@ public void toJson() throws IOException {
120120
LineString geo = LineString.fromJson(json);
121121
compareJson(json, geo.toJson());
122122
}
123+
124+
@Test
125+
public void fromJson_coordinatesPresent() throws Exception {
126+
thrown.expect(NullPointerException.class);
127+
LineString.fromJson("{\"type\":\"LineString\",\"coordinates\":null}");
128+
}
123129
}

services-geojson/src/test/java/com/mapbox/geojson/MultiLineStringTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
import static org.junit.Assert.assertNull;
77

88
import com.mapbox.core.TestUtils;
9+
10+
import org.junit.Rule;
911
import org.junit.Test;
12+
import org.junit.rules.ExpectedException;
1013

1114
import java.io.IOException;
1215
import java.util.ArrayList;
@@ -16,6 +19,9 @@ public class MultiLineStringTest extends TestUtils {
1619

1720
private static final String SAMPLE_MULTILINESTRING = "sample-multilinestring.json";
1821

22+
@Rule
23+
public ExpectedException thrown = ExpectedException.none();
24+
1925
@Test
2026
public void sanity() throws Exception {
2127
List<Point> points = new ArrayList<>();
@@ -133,4 +139,10 @@ public void toJson() throws IOException {
133139
MultiLineString geo = MultiLineString.fromJson(json);
134140
compareJson(json, geo.toJson());
135141
}
142+
143+
@Test
144+
public void fromJson_coordinatesPresent() throws Exception {
145+
thrown.expect(NullPointerException.class);
146+
MultiLineString.fromJson("{\"type\":\"MultiLineString\",\"coordinates\":null}");
147+
}
136148
}

services-geojson/src/test/java/com/mapbox/geojson/MultiPointTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
import com.mapbox.core.TestUtils;
99

10+
import org.junit.Rule;
1011
import org.junit.Test;
12+
import org.junit.rules.ExpectedException;
1113

1214
import java.io.IOException;
1315
import java.util.ArrayList;
@@ -17,6 +19,9 @@ public class MultiPointTest extends TestUtils {
1719

1820
private static final String SAMPLE_MULTIPOINT = "sample-multipoint.json";
1921

22+
@Rule
23+
public ExpectedException thrown = ExpectedException.none();
24+
2025
@Test
2126
public void sanity() throws Exception {
2227
List<Point> points = new ArrayList<>();
@@ -106,4 +111,10 @@ public void toJson() throws IOException {
106111
MultiPoint geo = MultiPoint.fromJson(json);
107112
compareJson(json, geo.toJson());
108113
}
114+
115+
@Test
116+
public void fromJson_coordinatesPresent() throws Exception {
117+
thrown.expect(NullPointerException.class);
118+
MultiPoint.fromJson("{\"type\":\"MultiPoint\",\"coordinates\":null}");
119+
}
109120
}

services-geojson/src/test/java/com/mapbox/geojson/MultiPolygonTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
import com.mapbox.core.TestUtils;
99

10+
import org.junit.Rule;
1011
import org.junit.Test;
12+
import org.junit.rules.ExpectedException;
1113

1214
import java.io.IOException;
1315
import java.util.ArrayList;
@@ -16,6 +18,9 @@
1618
public class MultiPolygonTest extends TestUtils {
1719
private static final String SAMPLE_MULTIPOLYGON = "sample-multipolygon.json";
1820

21+
@Rule
22+
public ExpectedException thrown = ExpectedException.none();
23+
1924
@Test
2025
public void sanity() throws Exception {
2126
List<Point> points = new ArrayList<>();
@@ -151,4 +156,10 @@ public void toJson() throws IOException {
151156
MultiPolygon geo = MultiPolygon.fromJson(json);
152157
compareJson(json, geo.toJson());
153158
}
159+
160+
@Test
161+
public void fromJson_coordinatesPresent() throws Exception {
162+
thrown.expect(NullPointerException.class);
163+
MultiPolygon.fromJson("{\"type\":\"MultiPolygon\",\"coordinates\":null}");
164+
}
154165
}

services-geojson/src/test/java/com/mapbox/geojson/PointTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import static org.junit.Assert.assertNull;
88

99
import com.mapbox.core.TestUtils;
10+
11+
import org.junit.Rule;
1012
import org.junit.Test;
13+
import org.junit.rules.ExpectedException;
1114

1215
import java.io.IOException;
1316
import java.util.ArrayList;
@@ -17,6 +20,9 @@ public class PointTest extends TestUtils {
1720

1821
private static final String SAMPLE_POINT = "sample-point.json";
1922

23+
@Rule
24+
public ExpectedException thrown = ExpectedException.none();
25+
2026
@Test
2127
public void sanity() throws Exception {
2228
Point point = Point.fromLngLat(1.0, 2.0);
@@ -60,7 +66,7 @@ public void bbox_nullWhenNotSet() throws Exception {
6066
}
6167

6268
@Test
63-
public void bbox_doesNotSerializeWhenNotPresent() throws Exception {
69+
public void bbox_doesSerializeWhenNotPresent() throws Exception {
6470
Point point = Point.fromLngLat(1.0, 2.0);
6571
compareJson(point.toJson(),
6672
"{\"type\":\"Point\",\"coordinates\":[1.0, 2.0]}");
@@ -126,4 +132,10 @@ public void toJson() throws IOException {
126132
Point geo = Point.fromJson(json);
127133
compareJson(json, geo.toJson());
128134
}
135+
136+
@Test
137+
public void fromJson_coordinatesPresent() throws Exception {
138+
thrown.expect(NullPointerException.class);
139+
Point.fromJson("{\"type\":\"Point\",\"coordinates\":null}");
140+
}
129141
}

services-geojson/src/test/java/com/mapbox/geojson/PolygonTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,10 @@ public void toJsonHoles() throws IOException {
264264
Polygon geo = Polygon.fromJson(json);
265265
compareJson(json, geo.toJson());
266266
}
267+
268+
@Test
269+
public void fromJson_coordinatesPresent() throws Exception {
270+
thrown.expect(NullPointerException.class);
271+
Polygon.fromJson("{\"type\":\"Polygon\",\"coordinates\":null}");
272+
}
267273
}

0 commit comments

Comments
 (0)