diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpChannelState.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpChannelState.java index 7c3c02c32ccd..73c14c076f7a 100644 --- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpChannelState.java +++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpChannelState.java @@ -1168,9 +1168,10 @@ else if (contentLength >= 0) else if (failure != null) { Throwable throwable = failure; + ByteBuffer slice = content != null ? content.slice() : BufferUtil.EMPTY_BUFFER; httpChannelState._serializedInvoker.run(() -> { - _listener.onResponseWrite(_request, last, content.slice(), throwable); + _listener.onResponseWrite(_request, last, slice, throwable); callback.failed(throwable); }); } @@ -1192,10 +1193,10 @@ else if (failure != null) { if (LOG.isDebugEnabled()) LOG.debug("writing last={} {} {}", last, BufferUtil.toDetailString(content), this); - ByteBuffer contentSlice = content.slice(); + ByteBuffer slice = content != null ? content.slice() : BufferUtil.EMPTY_BUFFER; Callback listenerCallback = Callback.from(() -> { - _listener.onResponseWrite(_request, last, contentSlice, null); + _listener.onResponseWrite(_request, last, slice, null); }, this); stream.send(_request._metaData, responseMetaData, last, content, listenerCallback); }