Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for NPE enclosed in SearchParseException for a "geo_shape" filter or query #8785

Merged
merged 1 commit into from Dec 10, 2014

Conversation

nknize
Copy link
Contributor

@nknize nknize commented Dec 4, 2014

...ter or query

This fix adds better error handling for parsing multipoint, linestring, and polygon GeoJSONs. Current logic throws a NPE when parsing a multipoint, linestring, or polygon that does not comply with the GeoJSON specification. That is, if a user provides a single coordinate instead of an array of coordinates, or array of linestrings, the ShapeParser throws a NPE wrapped in a SearchParseException instead of a more useful error message.

Closes #8432

@nknize nknize added :Analytics/Geo Indexing, search aggregations of geo points and shapes >bug v1.4.2 labels Dec 4, 2014
}
throw new ElasticsearchParseException("No data provided for multipoint object when expecting " +
">0 points (e.g., [[lat, lng]] or [[lat, lng], ...])");
} else if (!(coordinates.children.get(0) instanceof CoordinateNode)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use == false instead of ! it's so much easier to read and burned my fingers too often

@s1monw
Copy link
Contributor

s1monw commented Dec 4, 2014

left some minor comments - LGTM feel free to push if you fixes the nitpicks

@s1monw
Copy link
Contributor

s1monw commented Dec 4, 2014

should this go into 1.5 and 2.0 as well? can you label it?

throw new ElasticsearchParseException("No data provided for multipoint object when expecting " +
">0 points (e.g., [[lat, lng]] or [[lat, lng], ...])");
} else if (coordinates.children.get(0) instanceof CoordinateNode == false) {
throw new ElasticsearchParseException("multipoint expects an array of >=0 coordinates (e.g., [[lat, lng]]");
Copy link
Contributor

Choose a reason for hiding this comment

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

This message suggests that it is valid to have a multipoint with no coordinates, is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unlike LinearRing, LineString, and Polygon, the spec doesn't explicitly state a minimum number of points. Since you raised a very valid question - and as I think about more use cases - I think you're correct to point this out as not being user friendly. In fact, accepting 0 coordinates could lead to a lot of silent failures and extremely unhappy users.

I made the change to throw a Parse Exception if an empty array is provided. Good catch!

@colings86
Copy link
Contributor

LGTM

…filter or query

This fix adds better error handling for parsing multipoint, linestring, and polygon GeoJSONs.  Current logic throws a NPE when parsing a multipoint, linestring, or polygon that does not comply with the GeoJSON specification. That is, if a user provides a single coordinate instead of an array of coordinates, or array of linestrings, the ShapeParser throws a NPE wrapped in a SearchParseException instead of a more useful error message.

Closes elastic#8432
@nknize nknize merged commit aa644e3 into elastic:master Dec 10, 2014
@clintongormley clintongormley changed the title [GEO] Fix for NPE enclosed in SearchParseException for a "geo_shape" fil... Geo: Fix for NPE enclosed in SearchParseException for a "geo_shape" filter or query Dec 16, 2014
@clintongormley clintongormley changed the title Geo: Fix for NPE enclosed in SearchParseException for a "geo_shape" filter or query Fix for NPE enclosed in SearchParseException for a "geo_shape" filter or query Jun 7, 2015
@nknize nknize deleted the fix/8432 branch May 27, 2016 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/Geo Indexing, search aggregations of geo points and shapes >bug v1.4.2 v1.5.0 v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NPE enclosed in a SearchParseException for a "point" type "geo_shape" filter or query
3 participants