Program: 54849
Project: 54849
Buggy source:
/** 
 * Executes a direct media download or a resumable media download. <p> This method does not close the given output stream. </p> <p> This method is not reentrant. A new instance of   {@link MediaHttpDownloader} must beinstantiated before download called be called again. </p>
 * @param requestUrl The request URL where the download requests will be sent
 * @param requestHeaders request headers or {@code null} to ignore
 * @param outputStream destination output stream
 * @since 1.12
 */
public void download(GenericUrl requestUrl,HttpHeaders requestHeaders,OutputStream outputStream) throws IOException {
  Preconditions.checkArgument(downloadState == DownloadState.NOT_STARTED);
  requestUrl.put("String_Node_Str","String_Node_Str");
  if (directDownloadEnabled) {
    updateStateAndNotifyListener(DownloadState.MEDIA_IN_PROGRESS);
    HttpRequest request=requestFactory.buildGetRequest(requestUrl);
    if (requestHeaders != null) {
      request.getHeaders().putAll(requestHeaders);
    }
    HttpResponse response=request.execute();
    try {
      mediaContentLength=response.getHeaders().getContentLength();
      bytesDownloaded=mediaContentLength;
      updateStateAndNotifyListener(DownloadState.MEDIA_COMPLETE);
      AbstractInputStreamContent.copy(response.getContent(),outputStream);
    }
  finally {
      response.disconnect();
    }
    return;
  }
  while (true) {
    HttpRequest request=requestFactory.buildGetRequest(requestUrl);
    if (requestHeaders != null) {
      request.getHeaders().putAll(requestHeaders);
    }
    request.getHeaders().setRange("String_Node_Str" + bytesDownloaded + "String_Node_Str"+ (bytesDownloaded + chunkSize - 1));
    if (backOffPolicyEnabled) {
      request.setBackOffPolicy(new ExponentialBackOffPolicy());
    }
    HttpResponse response=request.execute();
    AbstractInputStreamContent.copy(response.getContent(),outputStream);
    String contentRange=response.getHeaders().getContentRange();
    long nextByteIndex=getNextByteIndex(contentRange);
    setMediaContentLength(contentRange);
    if (mediaContentLength <= nextByteIndex) {
      bytesDownloaded=mediaContentLength;
      updateStateAndNotifyListener(DownloadState.MEDIA_COMPLETE);
      return;
    }
    bytesDownloaded=nextByteIndex;
    updateStateAndNotifyListener(DownloadState.MEDIA_IN_PROGRESS);
  }
}

Fixed version (ground truth):
/** 
 * Executes a direct media download or a resumable media download. <p> This method does not close the given output stream. </p> <p> This method is not reentrant. A new instance of   {@link MediaHttpDownloader} must beinstantiated before download called be called again. </p>
 * @param requestUrl The request URL where the download requests will be sent
 * @param requestHeaders request headers or {@code null} to ignore
 * @param outputStream destination output stream
 * @since 1.12
 */
public void download(GenericUrl requestUrl,HttpHeaders requestHeaders,OutputStream outputStream) throws IOException {
  Preconditions.checkArgument(downloadState == DownloadState.NOT_STARTED);
  requestUrl.put("String_Node_Str","String_Node_Str");
  if (directDownloadEnabled) {
    updateStateAndNotifyListener(DownloadState.MEDIA_IN_PROGRESS);
    HttpRequest request=requestFactory.buildGetRequest(requestUrl);
    if (requestHeaders != null) {
      request.getHeaders().putAll(requestHeaders);
    }
    if (bytesDownloaded != 0) {
      request.getHeaders().setRange("String_Node_Str" + bytesDownloaded + "String_Node_Str");
    }
    HttpResponse response=request.execute();
    try {
      mediaContentLength=response.getHeaders().getContentLength();
      bytesDownloaded=mediaContentLength;
      updateStateAndNotifyListener(DownloadState.MEDIA_COMPLETE);
      AbstractInputStreamContent.copy(response.getContent(),outputStream);
    }
  finally {
      response.disconnect();
    }
    return;
  }
  while (true) {
    HttpRequest request=requestFactory.buildGetRequest(requestUrl);
    if (requestHeaders != null) {
      request.getHeaders().putAll(requestHeaders);
    }
    request.getHeaders().setRange("String_Node_Str" + bytesDownloaded + "String_Node_Str"+ (bytesDownloaded + chunkSize - 1));
    if (backOffPolicyEnabled) {
      request.setBackOffPolicy(new ExponentialBackOffPolicy());
    }
    HttpResponse response=request.execute();
    AbstractInputStreamContent.copy(response.getContent(),outputStream);
    String contentRange=response.getHeaders().getContentRange();
    long nextByteIndex=getNextByteIndex(contentRange);
    setMediaContentLength(contentRange);
    if (mediaContentLength <= nextByteIndex) {
      bytesDownloaded=mediaContentLength;
      updateStateAndNotifyListener(DownloadState.MEDIA_COMPLETE);
      return;
    }
    bytesDownloaded=nextByteIndex;
    updateStateAndNotifyListener(DownloadState.MEDIA_IN_PROGRESS);
  }
}