watcher: do not continue execution when get result doesn't exist

When attempting to a get a watch that does not exist, the listener is called once inside
an if statement and the execution of the method continues as if the watch existed. This
causes failures to happen including a NPE. This commit wraps the execution in a if-else
to prevent this.

Original commit: elastic/x-pack-elasticsearch@27f09852e7
This commit is contained in:
jaymode 2016-12-30 08:34:39 -05:00
parent 2b92ee71bc
commit 9c09b88e9f
1 changed files with 16 additions and 16 deletions

View File

@ -70,10 +70,7 @@ public class TransportGetWatchAction extends WatcherTransportAction<GetWatchRequ
}
client.getWatch(request.getId(), ActionListener.wrap(getResponse -> {
if (getResponse.isExists() == false) {
listener.onResponse(new GetWatchResponse(request.getId()));
}
if (getResponse.isExists()) {
try (XContentBuilder builder = jsonBuilder()) {
// When we return the watch via the Get Watch REST API, we want to return the watch as was specified in the put api,
// we don't include the status in the watch source itself, but as a separate top level field, so that
@ -88,6 +85,9 @@ public class TransportGetWatchAction extends WatcherTransportAction<GetWatchRequ
watch.status().version(getResponse.getVersion());
listener.onResponse(new GetWatchResponse(watch.id(), watch.status(), builder.bytes(), XContentType.JSON));
}
} else {
listener.onResponse(new GetWatchResponse(request.getId()));
}
}, listener::onFailure));
}