Fix NPE in Rest Layer when GET missing watch.
The REST GET API was trying to render a null watch on GET which was causing an NPE. Don't render the watch if it's not found and add a test for this case. Fixes: elastic/elasticsearch#202 Original commit: elastic/x-pack-elasticsearch@0c8afa63ba
This commit is contained in:
parent
a90d5a581e
commit
f5c50c44de
|
@ -0,0 +1,14 @@
|
||||||
|
---
|
||||||
|
"Test get watch api with missing watch":
|
||||||
|
- do:
|
||||||
|
cluster.health:
|
||||||
|
wait_for_status: green
|
||||||
|
|
||||||
|
|
||||||
|
- do:
|
||||||
|
watcher.get_watch:
|
||||||
|
id: "missing_watch"
|
||||||
|
ignore: 404
|
||||||
|
|
||||||
|
- match: { found : false}
|
||||||
|
- match: { _id: "missing_watch" }
|
|
@ -38,9 +38,11 @@ public class RestGetWatchAction extends WatcherRestHandler {
|
||||||
builder.startObject()
|
builder.startObject()
|
||||||
.field("found", response.isFound())
|
.field("found", response.isFound())
|
||||||
.field("_id", response.getId())
|
.field("_id", response.getId())
|
||||||
.field("_version", response.getVersion())
|
.field("_version", response.getVersion());
|
||||||
.field("watch", response.getSource(), ToXContent.EMPTY_PARAMS)
|
if (response.isFound()) {
|
||||||
.endObject();
|
builder.field("watch", response.getSource(), ToXContent.EMPTY_PARAMS);
|
||||||
|
}
|
||||||
|
builder.endObject();
|
||||||
|
|
||||||
RestStatus status = response.isFound() ? OK : NOT_FOUND;
|
RestStatus status = response.isFound() ? OK : NOT_FOUND;
|
||||||
return new BytesRestResponse(status, builder);
|
return new BytesRestResponse(status, builder);
|
||||||
|
|
Loading…
Reference in New Issue