From 8cc3c0dd93c9663d1583a6b6ea4bc1214caf713f Mon Sep 17 00:00:00 2001 From: Luca Cavanna Date: Wed, 31 Jul 2019 17:02:39 +0200 Subject: [PATCH] Remove task null check in TransportAction (#45014) The task that TaskManager#register returns cannot be null. The method enforces that it is not null after calling request#createTask. It is then needless to check for null in the listener later. Also, added the call to the delegate listener in a finally block, just to make sure. --- .../action/support/TransportAction.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/support/TransportAction.java b/server/src/main/java/org/elasticsearch/action/support/TransportAction.java index fcb4905b959..a500df5c643 100644 --- a/server/src/main/java/org/elasticsearch/action/support/TransportAction.java +++ b/server/src/main/java/org/elasticsearch/action/support/TransportAction.java @@ -64,14 +64,20 @@ public abstract class TransportAction() { @Override public void onResponse(Response response) { - taskManager.unregister(task); - listener.onResponse(response); + try { + taskManager.unregister(task); + } finally { + listener.onResponse(response); + } } @Override public void onFailure(Exception e) { - taskManager.unregister(task); - listener.onFailure(e); + try { + taskManager.unregister(task); + } finally { + listener.onFailure(e); + } } }); return task; @@ -86,18 +92,20 @@ public abstract class TransportAction() { @Override public void onResponse(Response response) { - if (task != null) { + try { taskManager.unregister(task); + } finally { + listener.onResponse(task, response); } - listener.onResponse(task, response); } @Override public void onFailure(Exception e) { - if (task != null) { + try { taskManager.unregister(task); + } finally { + listener.onFailure(task, e); } - listener.onFailure(task, e); } }); return task;