diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/util/BufferingResponseListener.java b/jetty-client/src/main/java/org/eclipse/jetty/client/util/BufferingResponseListener.java index b15083973e4..e30c6b90155 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/util/BufferingResponseListener.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/util/BufferingResponseListener.java @@ -103,10 +103,10 @@ public abstract class BufferingResponseListener extends Listener.Adapter int length = content.remaining(); if (length>BufferUtil.space(buffer)) { - int requiredCapacity = buffer.capacity()+length; + int requiredCapacity = buffer==null?0:buffer.capacity()+length; if (requiredCapacity>maxLength) response.abort(new IllegalArgumentException("Buffering capacity exceeded")); - + int newCapacity = Math.min(Integer.highestOneBit(requiredCapacity) << 1, maxLength); buffer = BufferUtil.ensureCapacity(buffer,newCapacity); }