diff --git a/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/UploadBufferPool.java b/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/UploadBufferPool.java index 96222f808bd7..b4590afc123e 100644 --- a/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/UploadBufferPool.java +++ b/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/UploadBufferPool.java @@ -112,10 +112,11 @@ public Flux write(ByteBuffer buf) { // We will overflow the current buffer and require another one. // Duplicate and adjust the window of buf so that we fill up currentBuf without going out of bounds. ByteBuffer duplicate = buf.duplicate(); - duplicate.limit(buf.position() + (int) this.currentBuf.remainingCapacity()); + int newLimit = buf.position() + (int) this.currentBuf.remainingCapacity(); + duplicate.limit(newLimit); this.currentBuf.append(duplicate); // Adjust the window of original buffer to represent remaining part. - buf.position(buf.position() + (int) this.currentBuf.remainingCapacity()); + buf.position(newLimit); result = Flux.just(this.currentBuf);