From 531bdbfdbc3cf69bebd6741bfe2cc624c98bebc4 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 19 Apr 2016 18:19:41 -0400 Subject: [PATCH] createTask can return null That is totally allowed. --- .../org/elasticsearch/tasks/TaskManager.java | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/tasks/TaskManager.java b/core/src/main/java/org/elasticsearch/tasks/TaskManager.java index 922f130af04..e7b0cb0068e 100644 --- a/core/src/main/java/org/elasticsearch/tasks/TaskManager.java +++ b/core/src/main/java/org/elasticsearch/tasks/TaskManager.java @@ -65,35 +65,35 @@ public class TaskManager extends AbstractComponent implements ClusterStateListen */ public Task register(String type, String action, TransportRequest request) { Task task = request.createTask(taskIdGenerator.incrementAndGet(), type, action, request.getParentTask()); + if (task == null) { + return null; + } assert task.getParentTaskId().equals(request.getParentTask()) : "Request [ " + request + "] didn't preserve it parentTaskId"; - if (task != null) { - if (logger.isTraceEnabled()) { - logger.trace("register {} [{}] [{}] [{}]", task.getId(), type, action, task.getDescription()); - } + if (logger.isTraceEnabled()) { + logger.trace("register {} [{}] [{}] [{}]", task.getId(), type, action, task.getDescription()); + } - if (task instanceof CancellableTask) { - CancellableTask cancellableTask = (CancellableTask) task; - CancellableTaskHolder holder = new CancellableTaskHolder(cancellableTask); - CancellableTaskHolder oldHolder = cancellableTasks.put(task.getId(), holder); - assert oldHolder == null; - // Check if this task was banned before we start it - if (task.getParentTaskId().isSet() && banedParents.isEmpty() == false) { - String reason = banedParents.get(task.getParentTaskId()); - if (reason != null) { - try { - holder.cancel(reason); - throw new IllegalStateException("Task cancelled before it started: " + reason); - } finally { - // let's clean up the registration - unregister(task); - } + if (task instanceof CancellableTask) { + CancellableTask cancellableTask = (CancellableTask) task; + CancellableTaskHolder holder = new CancellableTaskHolder(cancellableTask); + CancellableTaskHolder oldHolder = cancellableTasks.put(task.getId(), holder); + assert oldHolder == null; + // Check if this task was banned before we start it + if (task.getParentTaskId().isSet() && banedParents.isEmpty() == false) { + String reason = banedParents.get(task.getParentTaskId()); + if (reason != null) { + try { + holder.cancel(reason); + throw new IllegalStateException("Task cancelled before it started: " + reason); + } finally { + // let's clean up the registration + unregister(task); } } - } else { - Task previousTask = tasks.put(task.getId(), task); - assert previousTask == null; } - + } else { + Task previousTask = tasks.put(task.getId(), task); + assert previousTask == null; } return task; }