Program: 37574
Project: 37574
Buggy source:
/** 
 * Sends the HTTP request.
 * @param request           The request description.
 * @param resultClass       The class of the response from the service.
 * @param serializable      The object to send to the service in the body of the request.
 * @param progress          The progress callback for the request.
 * @param handler           The handler for stateful response.
 * @param < Result >          The type of the response object.
 * @param < Body >            The type of the object to send to the service in the body of the request.
 * @param < DeserializeType > The response handler for stateful response.
 * @return The result from the request.
 * @throws ClientException An exception occurs if the request was unable to complete for any reason.
 */
private <Result,Body,DeserializeType>Result sendRequestInternal(final IHttpRequest request,final Class<Result> resultClass,final Body serializable,final IProgressCallback<Result> progress,final IStatefulResponseHandler<Result,DeserializeType> handler) throws ClientException {
  final int defaultBufferSize=4096;
  final String contentLengthHeaderName="String_Node_Str";
  final String binaryContentType="String_Node_Str";
  try {
    if (authenticationProvider != null) {
      authenticationProvider.authenticateRequest(request);
    }
    OutputStream out=null;
    InputStream in=null;
    boolean isBinaryStreamInput=false;
    final URL requestUrl=request.getRequestUrl();
    logger.logDebug("String_Node_Str" + requestUrl.toString());
    final IConnection connection=connectionFactory.createFromRequest(request);
    try {
      logger.logDebug("String_Node_Str" + request.getHttpMethod().toString());
      List<HeaderOption> requestHeaders=request.getHeaders();
      final byte[] bytesToWrite;
      connection.addRequestHeader("String_Node_Str","String_Node_Str");
      if (serializable == null) {
        bytesToWrite=null;
      }
 else       if (serializable instanceof byte[]) {
        logger.logDebug("String_Node_Str");
        bytesToWrite=(byte[])serializable;
        if (!hasHeader(requestHeaders,CONTENT_TYPE_HEADER_NAME)) {
          connection.addRequestHeader(CONTENT_TYPE_HEADER_NAME,binaryContentType);
        }
        connection.setContentLength(bytesToWrite.length);
      }
 else {
        logger.logDebug("String_Node_Str" + serializable.getClass().getName() + "String_Node_Str");
        final String serializeObject=serializer.serializeObject(serializable);
        bytesToWrite=serializeObject.getBytes();
        if (!hasHeader(requestHeaders,CONTENT_TYPE_HEADER_NAME)) {
          connection.addRequestHeader(CONTENT_TYPE_HEADER_NAME,JSON_CONTENT_TYPE);
        }
        connection.setContentLength(bytesToWrite.length);
      }
      if (bytesToWrite != null) {
        out=connection.getOutputStream();
        int writtenSoFar=0;
        BufferedOutputStream bos=new BufferedOutputStream(out);
        int toWrite;
        do {
          toWrite=Math.min(defaultBufferSize,bytesToWrite.length - writtenSoFar);
          bos.write(bytesToWrite,writtenSoFar,toWrite);
          writtenSoFar=writtenSoFar + toWrite;
          if (progress != null) {
            executors.performOnForeground(writtenSoFar,bytesToWrite.length,progress);
          }
        }
 while (toWrite > 0);
        bos.close();
      }
      if (handler != null) {
        handler.configConnection(connection);
      }
      logger.logDebug(String.format("String_Node_Str",connection.getResponseCode(),connection.getResponseMessage()));
      if (handler != null) {
        logger.logDebug("String_Node_Str");
        return handler.generateResult(request,connection,this.getSerializer(),this.logger);
      }
      if (connection.getResponseCode() >= HttpResponseCode.HTTP_CLIENT_ERROR) {
        logger.logDebug("String_Node_Str");
        in=connection.getInputStream();
        handleErrorResponse(request,serializable,connection);
      }
      if (connection.getResponseCode() == HttpResponseCode.HTTP_NOBODY || connection.getResponseCode() == HttpResponseCode.HTTP_NOT_MODIFIED) {
        logger.logDebug("String_Node_Str");
        return handleEmptyResponse(connection.getResponseHeaders(),resultClass);
      }
      if (connection.getResponseCode() == HttpResponseCode.HTTP_ACCEPTED) {
        logger.logDebug("String_Node_Str");
        return handleEmptyResponse(connection.getResponseHeaders(),resultClass);
      }
      in=new BufferedInputStream(connection.getInputStream());
      final Map<String,String> headers=connection.getHeaders();
      final String contentType=headers.get(CONTENT_TYPE_HEADER_NAME);
      if (contentType.contains(JSON_CONTENT_TYPE)) {
        logger.logDebug("String_Node_Str");
        return handleJsonResponse(in,connection.getResponseHeaders(),resultClass);
      }
 else {
        logger.logDebug("String_Node_Str");
        isBinaryStreamInput=true;
        return (Result)handleBinaryStream(in);
      }
    }
  finally {
      if (out != null) {
        out.close();
      }
      if (!isBinaryStreamInput && in != null) {
        in.close();
        connection.close();
      }
    }
  }
 catch (  final GraphServiceException ex) {
    final boolean shouldLogVerbosely=logger.getLoggingLevel() == LoggerLevel.DEBUG;
    logger.logError("String_Node_Str" + ex.getMessage(shouldLogVerbosely),ex);
    throw ex;
  }
catch (  final Exception ex) {
    final ClientException clientException=new ClientException("String_Node_Str",ex);
    logger.logError("String_Node_Str",clientException);
    throw clientException;
  }
}

Fixed version (ground truth):
/** 
 * Sends the HTTP request.
 * @param request           The request description.
 * @param resultClass       The class of the response from the service.
 * @param serializable      The object to send to the service in the body of the request.
 * @param progress          The progress callback for the request.
 * @param handler           The handler for stateful response.
 * @param < Result >          The type of the response object.
 * @param < Body >            The type of the object to send to the service in the body of the request.
 * @param < DeserializeType > The response handler for stateful response.
 * @return The result from the request.
 * @throws ClientException An exception occurs if the request was unable to complete for any reason.
 */
private <Result,Body,DeserializeType>Result sendRequestInternal(final IHttpRequest request,final Class<Result> resultClass,final Body serializable,final IProgressCallback<Result> progress,final IStatefulResponseHandler<Result,DeserializeType> handler) throws ClientException {
  final int defaultBufferSize=4096;
  final String binaryContentType="String_Node_Str";
  try {
    if (authenticationProvider != null) {
      authenticationProvider.authenticateRequest(request);
    }
    OutputStream out=null;
    InputStream in=null;
    boolean isBinaryStreamInput=false;
    final URL requestUrl=request.getRequestUrl();
    logger.logDebug("String_Node_Str" + requestUrl.toString());
    final IConnection connection=connectionFactory.createFromRequest(request);
    try {
      logger.logDebug("String_Node_Str" + request.getHttpMethod().toString());
      List<HeaderOption> requestHeaders=request.getHeaders();
      final byte[] bytesToWrite;
      connection.addRequestHeader("String_Node_Str","String_Node_Str");
      if (serializable == null) {
        if (request.getHttpMethod() == HttpMethod.POST) {
          bytesToWrite=new byte[0];
        }
 else {
          bytesToWrite=null;
        }
      }
 else       if (serializable instanceof byte[]) {
        logger.logDebug("String_Node_Str");
        bytesToWrite=(byte[])serializable;
        if (!hasHeader(requestHeaders,CONTENT_TYPE_HEADER_NAME)) {
          connection.addRequestHeader(CONTENT_TYPE_HEADER_NAME,binaryContentType);
        }
        connection.setContentLength(bytesToWrite.length);
      }
 else {
        logger.logDebug("String_Node_Str" + serializable.getClass().getName() + "String_Node_Str");
        final String serializeObject=serializer.serializeObject(serializable);
        bytesToWrite=serializeObject.getBytes();
        if (!hasHeader(requestHeaders,CONTENT_TYPE_HEADER_NAME)) {
          connection.addRequestHeader(CONTENT_TYPE_HEADER_NAME,JSON_CONTENT_TYPE);
        }
        connection.setContentLength(bytesToWrite.length);
      }
      if (bytesToWrite != null) {
        out=connection.getOutputStream();
        int writtenSoFar=0;
        BufferedOutputStream bos=new BufferedOutputStream(out);
        int toWrite;
        do {
          toWrite=Math.min(defaultBufferSize,bytesToWrite.length - writtenSoFar);
          bos.write(bytesToWrite,writtenSoFar,toWrite);
          writtenSoFar=writtenSoFar + toWrite;
          if (progress != null) {
            executors.performOnForeground(writtenSoFar,bytesToWrite.length,progress);
          }
        }
 while (toWrite > 0);
        bos.close();
      }
      if (handler != null) {
        handler.configConnection(connection);
      }
      logger.logDebug(String.format("String_Node_Str",connection.getResponseCode(),connection.getResponseMessage()));
      if (handler != null) {
        logger.logDebug("String_Node_Str");
        return handler.generateResult(request,connection,this.getSerializer(),this.logger);
      }
      if (connection.getResponseCode() >= HttpResponseCode.HTTP_CLIENT_ERROR) {
        logger.logDebug("String_Node_Str");
        in=connection.getInputStream();
        handleErrorResponse(request,serializable,connection);
      }
      if (connection.getResponseCode() == HttpResponseCode.HTTP_NOBODY || connection.getResponseCode() == HttpResponseCode.HTTP_NOT_MODIFIED) {
        logger.logDebug("String_Node_Str");
        return handleEmptyResponse(connection.getResponseHeaders(),resultClass);
      }
      if (connection.getResponseCode() == HttpResponseCode.HTTP_ACCEPTED) {
        logger.logDebug("String_Node_Str");
        return handleEmptyResponse(connection.getResponseHeaders(),resultClass);
      }
      in=new BufferedInputStream(connection.getInputStream());
      final Map<String,String> headers=connection.getHeaders();
      final String contentType=headers.get(CONTENT_TYPE_HEADER_NAME);
      if (contentType.contains(JSON_CONTENT_TYPE)) {
        logger.logDebug("String_Node_Str");
        return handleJsonResponse(in,connection.getResponseHeaders(),resultClass);
      }
 else {
        logger.logDebug("String_Node_Str");
        isBinaryStreamInput=true;
        return (Result)handleBinaryStream(in);
      }
    }
  finally {
      if (out != null) {
        out.close();
      }
      if (!isBinaryStreamInput && in != null) {
        in.close();
        connection.close();
      }
    }
  }
 catch (  final GraphServiceException ex) {
    final boolean shouldLogVerbosely=logger.getLoggingLevel() == LoggerLevel.DEBUG;
    logger.logError("String_Node_Str" + ex.getMessage(shouldLogVerbosely),ex);
    throw ex;
  }
catch (  final Exception ex) {
    final ClientException clientException=new ClientException("String_Node_Str",ex);
    logger.logError("String_Node_Str",clientException);
    throw clientException;
  }
}