Program: 54845
Project: 54845
Buggy source:
/** 
 * Sets the HTTP media content chunk and the required headers that should be used in the upload request.
 * @param bytesWritten The number of bytes that have been successfully uploaded on the server
 */
private void setContentAndHeadersOnCurrentRequest(long bytesWritten) throws IOException {
  int blockSize;
  if (getMediaContentLength() >= 0) {
    blockSize=(int)Math.min(chunkSize,getMediaContentLength() - bytesWritten);
  }
 else {
    blockSize=chunkSize;
  }
  AbstractInputStreamContent contentChunk;
  int actualBlockSize=blockSize;
  String mediaContentLengthStr;
  if (getMediaContentLength() >= 0) {
    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 contentBufferStartIndex=0;
    if (currentRequestContentBuffer == null) {
      bytesAllowedToRead=cachedByte == null ? blockSize + 1 : blockSize;
      InputStream limitInputStream=ByteStreams.limit(contentInputStream,bytesAllowedToRead);
      currentRequestContentBuffer=new byte[blockSize + 1];
      if (cachedByte != null) {
        currentRequestContentBuffer[0]=cachedByte;
      }
      actualBytesRead=limitInputStream.read(currentRequestContentBuffer,blockSize + 1 - bytesAllowedToRead,bytesAllowedToRead);
    }
 else {
      bytesAllowedToRead=(int)(chunkSize - (bytesWritten - bytesUploaded) + 1);
      contentBufferStartIndex=(int)(bytesWritten - bytesUploaded);
      actualBytesRead=bytesAllowedToRead;
    }
    if (actualBytesRead < bytesAllowedToRead) {
      actualBlockSize=Math.max(0,actualBytesRead);
      if (cachedByte != null) {
        actualBlockSize++;
      }
      mediaContentLengthStr=String.valueOf(bytesWritten + actualBlockSize);
    }
 else {
      cachedByte=currentRequestContentBuffer[blockSize];
      mediaContentLengthStr="String_Node_Str";
    }
    contentChunk=new ByteArrayContent(mediaContent.getType(),currentRequestContentBuffer,contentBufferStartIndex,actualBlockSize);
  }
  currentRequest.setContent(contentChunk);
  if (actualBlockSize == 0) {
    currentRequest.getHeaders().setContentRange("String_Node_Str");
  }
 else {
    currentRequest.getHeaders().setContentRange("String_Node_Str" + bytesWritten + "String_Node_Str"+ (bytesWritten + 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.
 * @param bytesWritten The number of bytes that have been successfully uploaded on the server
 */
private void setContentAndHeadersOnCurrentRequest(long bytesWritten) throws IOException {
  int blockSize;
  if (getMediaContentLength() >= 0) {
    blockSize=(int)Math.min(chunkSize,getMediaContentLength() - bytesWritten);
  }
 else {
    blockSize=chunkSize;
  }
  AbstractInputStreamContent contentChunk;
  int actualBlockSize=blockSize;
  String mediaContentLengthStr;
  if (getMediaContentLength() >= 0) {
    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 contentBufferStartIndex=0;
    if (currentRequestContentBuffer == null) {
      bytesAllowedToRead=cachedByte == null ? blockSize + 1 : blockSize;
      currentRequestContentBuffer=new byte[blockSize + 1];
      if (cachedByte != null) {
        currentRequestContentBuffer[0]=cachedByte;
      }
      actualBytesRead=ByteStreams.read(contentInputStream,currentRequestContentBuffer,blockSize + 1 - bytesAllowedToRead,bytesAllowedToRead);
    }
 else {
      bytesAllowedToRead=(int)(chunkSize - (bytesWritten - bytesUploaded) + 1);
      contentBufferStartIndex=(int)(bytesWritten - bytesUploaded);
      actualBytesRead=bytesAllowedToRead;
    }
    if (actualBytesRead < bytesAllowedToRead) {
      actualBlockSize=Math.max(0,actualBytesRead);
      if (cachedByte != null) {
        actualBlockSize++;
      }
      mediaContentLengthStr=String.valueOf(bytesWritten + actualBlockSize);
    }
 else {
      cachedByte=currentRequestContentBuffer[blockSize];
      mediaContentLengthStr="String_Node_Str";
    }
    contentChunk=new ByteArrayContent(mediaContent.getType(),currentRequestContentBuffer,contentBufferStartIndex,actualBlockSize);
  }
  currentRequest.setContent(contentChunk);
  if (actualBlockSize == 0) {
    currentRequest.getHeaders().setContentRange("String_Node_Str");
  }
 else {
    currentRequest.getHeaders().setContentRange("String_Node_Str" + bytesWritten + "String_Node_Str"+ (bytesWritten + actualBlockSize - 1)+ "String_Node_Str"+ mediaContentLengthStr);
  }
}