Program: 54836
Project: 54836
Buggy source:
/** 
 * Sets the HTTP media content chunk and the required headers that should be used in the upload request.
 */
private void setContentAndHeadersOnCurrentRequest() throws IOException {
  int blockSize;
  if (isMediaLengthKnown()) {
    blockSize=(int)Math.min(chunkSize,getMediaContentLength() - totalBytesServerReceived);
  }
 else {
    blockSize=chunkSize;
  }
  AbstractInputStreamContent contentChunk;
  int actualBlockSize=blockSize;
  String mediaContentLengthStr;
  if (isMediaLengthKnown()) {
    contentInputStream.mark(blockSize);
    InputStream limitInputStream=ByteStreams.limit(contentInputStream,blockSize);
    contentChunk=new InputStreamContent(mediaContent.getType(),limitInputStream).setRetrySupported(true).setLength(blockSize).setCloseInputStream(false);
    mediaContentLengthStr=String.valueOf(getMediaContentLength());
  }
 else {
    int actualBytesRead;
    int bytesAllowedToRead;
    int copyBytes=0;
    if (currentRequestContentBuffer == null) {
      totalBytesClientSent+=currentChunkLength;
      bytesAllowedToRead=cachedByte == null ? blockSize + 1 : blockSize;
      currentRequestContentBuffer=new byte[blockSize + 1];
      if (cachedByte != null) {
        currentRequestContentBuffer[0]=cachedByte;
      }
    }
 else {
      copyBytes=(currentChunkLength - (int)(totalBytesServerReceived - totalBytesClientSent));
      totalBytesClientSent=totalBytesServerReceived;
      System.arraycopy(currentRequestContentBuffer,currentChunkLength - copyBytes,currentRequestContentBuffer,0,copyBytes);
      if (cachedByte != null) {
        currentRequestContentBuffer[copyBytes]=cachedByte;
        cachedByte=null;
      }
      bytesAllowedToRead=blockSize - copyBytes;
    }
    actualBytesRead=ByteStreams.read(contentInputStream,currentRequestContentBuffer,blockSize + 1 - bytesAllowedToRead,bytesAllowedToRead);
    if (actualBytesRead < bytesAllowedToRead || bytesAllowedToRead == 0) {
      actualBlockSize=copyBytes + Math.max(0,actualBytesRead);
      if (cachedByte != null) {
        actualBlockSize++;
        cachedByte=null;
      }
      mediaContentLengthStr=String.valueOf(totalBytesServerReceived + actualBlockSize);
    }
 else {
      cachedByte=currentRequestContentBuffer[blockSize];
      mediaContentLengthStr="String_Node_Str";
    }
    contentChunk=new ByteArrayContent(mediaContent.getType(),currentRequestContentBuffer,0,actualBlockSize);
  }
  currentChunkLength=actualBlockSize;
  currentRequest.setContent(contentChunk);
  if (actualBlockSize == 0) {
    currentRequest.getHeaders().setContentRange("String_Node_Str");
  }
 else {
    currentRequest.getHeaders().setContentRange("String_Node_Str" + totalBytesServerReceived + "String_Node_Str"+ (totalBytesServerReceived + actualBlockSize - 1)+ "String_Node_Str"+ mediaContentLengthStr);
  }
}

Fixed version (ground truth):
/** 
 * Sets the HTTP media content chunk and the required headers that should be used in the upload request.
 */
private void setContentAndHeadersOnCurrentRequest() throws IOException {
  int blockSize;
  if (isMediaLengthKnown()) {
    blockSize=(int)Math.min(chunkSize,getMediaContentLength() - totalBytesServerReceived);
  }
 else {
    blockSize=chunkSize;
  }
  AbstractInputStreamContent contentChunk;
  int actualBlockSize=blockSize;
  if (isMediaLengthKnown()) {
    contentInputStream.mark(blockSize);
    InputStream limitInputStream=ByteStreams.limit(contentInputStream,blockSize);
    contentChunk=new InputStreamContent(mediaContent.getType(),limitInputStream).setRetrySupported(true).setLength(blockSize).setCloseInputStream(false);
    mediaContentLengthStr=String.valueOf(getMediaContentLength());
  }
 else {
    int actualBytesRead;
    int bytesAllowedToRead;
    int copyBytes=0;
    if (currentRequestContentBuffer == null) {
      bytesAllowedToRead=cachedByte == null ? blockSize + 1 : blockSize;
      currentRequestContentBuffer=new byte[blockSize + 1];
      if (cachedByte != null) {
        currentRequestContentBuffer[0]=cachedByte;
      }
    }
 else {
      copyBytes=(int)(totalBytesClientSent - totalBytesServerReceived);
      System.arraycopy(currentRequestContentBuffer,currentChunkLength - copyBytes,currentRequestContentBuffer,0,copyBytes);
      if (cachedByte != null) {
        currentRequestContentBuffer[copyBytes]=cachedByte;
      }
      bytesAllowedToRead=blockSize - copyBytes;
    }
    actualBytesRead=ByteStreams.read(contentInputStream,currentRequestContentBuffer,blockSize + 1 - bytesAllowedToRead,bytesAllowedToRead);
    if (actualBytesRead < bytesAllowedToRead) {
      actualBlockSize=copyBytes + Math.max(0,actualBytesRead);
      if (cachedByte != null) {
        actualBlockSize++;
        cachedByte=null;
      }
      if (mediaContentLengthStr.equals("String_Node_Str")) {
        mediaContentLengthStr=String.valueOf(totalBytesServerReceived + actualBlockSize);
      }
    }
 else {
      cachedByte=currentRequestContentBuffer[blockSize];
    }
    contentChunk=new ByteArrayContent(mediaContent.getType(),currentRequestContentBuffer,0,actualBlockSize);
    totalBytesClientSent=totalBytesServerReceived + actualBlockSize;
  }
  currentChunkLength=actualBlockSize;
  currentRequest.setContent(contentChunk);
  if (actualBlockSize == 0) {
    currentRequest.getHeaders().setContentRange("String_Node_Str");
  }
 else {
    currentRequest.getHeaders().setContentRange("String_Node_Str" + totalBytesServerReceived + "String_Node_Str"+ (totalBytesServerReceived + actualBlockSize - 1)+ "String_Node_Str"+ mediaContentLengthStr);
  }
}