Skip to content

Commit 6d2c9c3

Browse files
committed
avoid 500 error for invalid point
1 parent 03f9e4e commit 6d2c9c3

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

core/src/main/java/com/graphhopper/routing/Router.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public GHResponse route(GHRequest request) {
9898
try {
9999
checkNoLegacyParameters(request);
100100
checkAtLeastOnePoint(request);
101-
checkIfPointsAreInBounds(request.getPoints());
101+
checkIfPointsAreInBoundsAndNotNull(request.getPoints());
102102
checkHeadings(request);
103103
checkPointHints(request);
104104
checkCurbsides(request);
@@ -147,13 +147,14 @@ private void checkAtLeastOnePoint(GHRequest request) {
147147
throw new IllegalArgumentException("You have to pass at least one point");
148148
}
149149

150-
private void checkIfPointsAreInBounds(List<GHPoint> points) {
150+
private void checkIfPointsAreInBoundsAndNotNull(List<GHPoint> points) {
151151
BBox bounds = graph.getBounds();
152152
for (int i = 0; i < points.size(); i++) {
153153
GHPoint point = points.get(i);
154-
if (!bounds.contains(point.getLat(), point.getLon())) {
154+
if (point == null)
155+
throw new IllegalArgumentException("Point " + i + " is null");
156+
if (!bounds.contains(point.getLat(), point.getLon()))
155157
throw new PointOutOfBoundsException("Point " + i + " is out of bounds: " + point + ", the bounds are: " + bounds, i);
156-
}
157158
}
158159
}
159160

web-api/src/main/java/com/graphhopper/jackson/GHPointDeserializer.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.graphhopper.jackson;
1919

2020
import com.fasterxml.jackson.core.JsonParser;
21+
import com.fasterxml.jackson.core.JsonProcessingException;
2122
import com.fasterxml.jackson.databind.DeserializationContext;
2223
import com.fasterxml.jackson.databind.JsonDeserializer;
2324
import com.graphhopper.util.shapes.GHPoint;
@@ -27,7 +28,11 @@
2728
class GHPointDeserializer extends JsonDeserializer<GHPoint> {
2829
@Override
2930
public GHPoint deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
30-
double[] bounds = jsonParser.readValueAs(double[].class);
31-
return GHPoint.fromJson(bounds);
31+
try {
32+
double[] bounds = jsonParser.readValueAs(double[].class);
33+
return GHPoint.fromJson(bounds);
34+
} catch (JsonProcessingException ex) {
35+
throw new IllegalArgumentException("point is invalid: " + ex.getMessage());
36+
}
3237
}
3338
}

0 commit comments

Comments
 (0)