From 9aa8eef59884cd8c75d6460a711566c10f2aef5b Mon Sep 17 00:00:00 2001 From: sid-evolphin <102239119+sid-evolphin@users.noreply.github.com> Date: Tue, 20 Jun 2023 15:11:33 +0530 Subject: [PATCH] Issue #9476 Fixed null Callback usages in HttpConnection.SendCallback 1. Fixed the usages of `Callback` returned by `o.e.j.s.HttpConnection.SendCallback.release()` to check for `null` before invoking the `failedCallback(Callback, Throwable)` or `succeeded()` methods. 2. Also, added a try-finally block around the Callback invocations in order to ensure that shutdownOutput will get performed irrespective of whether they end up throwing any exception. --- .../eclipse/jetty/server/HttpConnection.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java index b61b201d6d61..64ec7ada695f 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java @@ -897,17 +897,27 @@ private void releaseChunk() @Override protected void onCompleteSuccess() { - release().succeeded(); - if (_shutdownOut) - getEndPoint().shutdownOutput(); + Callback callback = release(); + try { + if (callback != null) + callback.succeeded(); + } finally { + if (_shutdownOut) + getEndPoint().shutdownOutput(); + } } @Override public void onCompleteFailure(final Throwable x) { - failedCallback(release(), x); - if (_shutdownOut) - getEndPoint().shutdownOutput(); + Callback callback = release(); + try { + if (callback != null) + failedCallback(callback, x); + } finally { + if (_shutdownOut) + getEndPoint().shutdownOutput(); + } } @Override