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.
This commit is contained in:
Luca Cavanna 2019-07-31 17:02:39 +02:00
parent e85b53a955
commit 8cc3c0dd93
1 changed files with 16 additions and 8 deletions

View File

@ -64,14 +64,20 @@ public abstract class TransportAction<Request extends ActionRequest, Response ex
execute(task, request, new ActionListener<Response>() {
@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<Request extends ActionRequest, Response ex
execute(task, request, new ActionListener<Response>() {
@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;