[ML] Fix NullPointerException when deleting a job with state "opening" (elastic/x-pack-elasticsearch#1769)
relates elastic/x-pack-elasticsearch#1768
Original commit: elastic/x-pack-elasticsearch@ae1f431316588c95dbf24f67a4d75e9f05dde6b3
@@ -365,8 +365,9 @@ public class MlMetadata implements MetaData.Custom {
if (allowDeleteOpenJob == false) {
PersistentTask<?> jobTask = getJobTask(jobId, tasks);
if (jobTask != null) {
+ JobTaskStatus jobTaskStatus = (JobTaskStatus) jobTask.getStatus();
throw ExceptionsHelper.conflictStatusException("Cannot delete job [" + jobId + "] because the job is "
- + ((JobTaskStatus) jobTask.getStatus()).getState());
+ + ((jobTaskStatus == null) ? JobState.OPENING : jobTaskStatus.getState()));
}
}
Job.Builder jobBuilder = new Job.Builder(job);
