Source:
<code>void fillChunks() { try { PutChunk chunkToFill; while (!isChunkFillingDone()) { if (channelReadBuffer == null) { channelReadBuffer = chunkFillerChannel.getNextChunk(0); } if (channelReadBuffer != null) { maybeStopTrackingWaitForChannelDataTime(); chunkToFill = getChunkToFill(); if (chunkToFill == null) { maybeStartTrackingWaitForChunkTime(); break; } else { maybeStopTrackingWaitForChunkTime(); bytesFilledSoFar += chunkToFill.fillFrom(channelReadBuffer); if (chunkToFill.isReady()) { routerCallback.onPollReady(); updateChunkFillerWaitTimeMetrics(); } if (!channelReadBuffer.hasRemaining()) { chunkFillerChannel.resolveOldestChunk(null); channelReadBuffer = null; } } } else { if (getFreeChunk() != null) { maybeStartTrackingWaitForChannelDataTime(); } break; } } if (chunkFillingCompletedSuccessfully) { PutChunk lastChunk = getBuildingChunk(); if (lastChunk != null) { <START> if (chunkCounter != 0 && lastChunk.buf.position() == 0) { <END> logger.trace("The last chunk received from ReadableStreamChannel has no data, discarding"); } else { lastChunk.onFillComplete(true); updateChunkFillerWaitTimeMetrics(); } } routerCallback.onPollReady(); } } catch (Exception e) { RouterException routerException = e instanceof RouterException ? (RouterException) e : new RouterException("PutOperation fillChunks encountered unexpected error", e, RouterErrorCode.UnexpectedInternalError); routerMetrics.chunkFillerUnexpectedErrorCount.inc(); routerCallback.onPollReady(); setOperationExceptionAndComplete(routerException); } }</code><technical_language>lastChunk.buf.position() == 0 is a reliable check buffers position > 0 data position == limit. Also, if zero sized buffers in middle? I fine - a test useful (if there)</technical_language>

Target:
void fillChunks() { try { PutChunk chunkToFill; while (!isChunkFillingDone()) { if (channelReadBuffer == null) { channelReadBuffer = chunkFillerChannel.getNextChunk(0); } if (channelReadBuffer != null) { maybeStopTrackingWaitForChannelDataTime(); chunkToFill = getChunkToFill(); if (chunkToFill == null) { maybeStartTrackingWaitForChunkTime(); break; } else { maybeStopTrackingWaitForChunkTime(); bytesFilledSoFar += chunkToFill.fillFrom(channelReadBuffer); if (chunkToFill.isReady()) { routerCallback.onPollReady(); updateChunkFillerWaitTimeMetrics(); } if (!channelReadBuffer.hasRemaining()) { chunkFillerChannel.resolveOldestChunk(null); channelReadBuffer = null; } } } else { if (getFreeChunk() != null) { maybeStartTrackingWaitForChannelDataTime(); } break; } } if (chunkFillingCompletedSuccessfully) { PutChunk lastChunk = getBuildingChunk(); if (lastChunk != null) { if (chunkCounter != 0 && lastChunk.buf.position() == 0) { logger.trace("The last buffer(s) received from chunkFillerChannel have no data, discarding them."); } else { lastChunk.onFillComplete(true); updateChunkFillerWaitTimeMetrics(); } } routerCallback.onPollReady(); } } catch (Exception e) { RouterException routerException = e instanceof RouterException ? (RouterException) e : new RouterException("PutOperation fillChunks encountered unexpected error", e, RouterErrorCode.UnexpectedInternalError); routerMetrics.chunkFillerUnexpectedErrorCount.inc(); routerCallback.onPollReady(); setOperationExceptionAndComplete(routerException); } }