From 71149fb6d4fd533f99d82a45b4276e887645608f Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 4 Apr 2017 16:15:56 +0200 Subject: [PATCH] [ML] Fix NPE Original commit: elastic/x-pack-elasticsearch@421491bce00cb23d7f9c8a486ac53ead8a645d69 --- .../elasticsearch/xpack/ml/action/CloseJobAction.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/CloseJobAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/CloseJobAction.java index d559869138d..d232ef52501 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/CloseJobAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/CloseJobAction.java @@ -249,8 +249,13 @@ public class CloseJobAction extends Action jobTask = MlMetadata.getJobTask(request.getJobId(), tasks); - forceCloseJob(jobTask.getId(), request.getJobId(), listener); + String jobId = request.getJobId(); + PersistentTask jobTask = MlMetadata.getJobTask(jobId, tasks); + if (jobTask == null) { + throw new ElasticsearchStatusException("cannot force close job, because job [" + jobId + "] is not open", + RestStatus.CONFLICT); + } + forceCloseJob(jobTask.getId(), jobId, listener); } else { PersistentTask jobTask = validateAndReturnJobTask(request.getJobId(), currentState); normalCloseJob(task, jobTask.getId(), request, listener);