Program: 7531
Project: 7531
Buggy source:
@POST @Path("String_Node_Str") public void downloadQueryResults(HttpRequest request,HttpResponder responder,@PathParam("String_Node_Str") final String id){
  boolean responseStarted=false;
  try {
    QueryHandle handle=QueryHandle.fromId(id);
    if (handle.equals(QueryHandle.NO_OP)) {
      responder.sendString(HttpResponseStatus.OK,"String_Node_Str");
      return;
    }
    StringBuffer sb=new StringBuffer();
    sb.append(getCSVHeaders(exploreService.getResultSchema(handle)));
    sb.append('\n');
    List<QueryResult> results;
    results=exploreService.previewResults(handle);
    if (results.isEmpty()) {
      results=exploreService.nextResults(handle,DOWNLOAD_FETCH_CHUNK_SIZE);
    }
    try {
      responder.sendChunkStart(HttpResponseStatus.OK,null);
      responseStarted=true;
      while (!results.isEmpty()) {
        for (        QueryResult result : results) {
          appendCSVRow(sb,result);
          sb.append('\n');
        }
        responder.sendChunk(ChannelBuffers.wrappedBuffer(sb.toString().getBytes("String_Node_Str")));
        sb=new StringBuffer();
        results=exploreService.nextResults(handle,DOWNLOAD_FETCH_CHUNK_SIZE);
      }
    }
  finally {
      responder.sendChunkEnd();
    }
  }
 catch (  IllegalArgumentException e) {
    LOG.debug("String_Node_Str",e);
    if (!responseStarted) {
      responder.sendError(HttpResponseStatus.BAD_REQUEST,e.getMessage());
    }
  }
catch (  SQLException e) {
    LOG.debug("String_Node_Str",e);
    if (!responseStarted) {
      responder.sendError(HttpResponseStatus.BAD_REQUEST,String.format("String_Node_Str",e.getSQLState(),e.getMessage()));
    }
  }
catch (  HandleNotFoundException e) {
    if (!responseStarted) {
      responder.sendStatus(HttpResponseStatus.NOT_FOUND);
    }
  }
catch (  Throwable e) {
    LOG.error("String_Node_Str",e);
    if (!responseStarted) {
      responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
    }
  }
}

Fixed version (ground truth):
@POST @Path("String_Node_Str") public void downloadQueryResults(HttpRequest request,HttpResponder responder,@PathParam("String_Node_Str") final String id){
  boolean responseStarted=false;
  try {
    QueryHandle handle=QueryHandle.fromId(id);
    if (handle.equals(QueryHandle.NO_OP)) {
      responder.sendStatus(HttpResponseStatus.CONFLICT);
      return;
    }
    StringBuffer sb=new StringBuffer();
    sb.append(getCSVHeaders(exploreService.getResultSchema(handle)));
    sb.append('\n');
    List<QueryResult> results;
    results=exploreService.previewResults(handle);
    if (results.isEmpty()) {
      results=exploreService.nextResults(handle,DOWNLOAD_FETCH_CHUNK_SIZE);
    }
    try {
      responder.sendChunkStart(HttpResponseStatus.OK,null);
      responseStarted=true;
      while (!results.isEmpty()) {
        for (        QueryResult result : results) {
          appendCSVRow(sb,result);
          sb.append('\n');
        }
        responder.sendChunk(ChannelBuffers.wrappedBuffer(sb.toString().getBytes("String_Node_Str")));
        sb.delete(0,sb.length());
        results=exploreService.nextResults(handle,DOWNLOAD_FETCH_CHUNK_SIZE);
      }
    }
  finally {
      responder.sendChunkEnd();
    }
  }
 catch (  IllegalArgumentException e) {
    LOG.debug("String_Node_Str",e);
    if (!responseStarted) {
      responder.sendError(HttpResponseStatus.BAD_REQUEST,e.getMessage());
    }
  }
catch (  SQLException e) {
    LOG.debug("String_Node_Str",e);
    if (!responseStarted) {
      responder.sendError(HttpResponseStatus.BAD_REQUEST,String.format("String_Node_Str",e.getSQLState(),e.getMessage()));
    }
  }
catch (  HandleNotFoundException e) {
    if (!responseStarted) {
      responder.sendStatus(HttpResponseStatus.NOT_FOUND);
    }
  }
catch (  Throwable e) {
    LOG.error("String_Node_Str",e);
    if (!responseStarted) {
      responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
    }
  }
}