Program: 119422
Project: 119422
Buggy source:
private List<BatchInfo> createBatchesFromCSVFile() throws IOException, AsyncApiException {
  List<BatchInfo> batchInfos=new ArrayList<BatchInfo>();
  BufferedReader rdr=new BufferedReader(new InputStreamReader(new FileInputStream(bulkFileName),FILE_ENCODING));
  byte[] headerBytes=(rdr.readLine() + "String_Node_Str").getBytes("String_Node_Str");
  int headerBytesLength=headerBytes.length;
  File tmpFile=File.createTempFile("String_Node_Str","String_Node_Str");
  try {
    FileOutputStream tmpOut=new FileOutputStream(tmpFile);
    int currentBytes=0;
    int currentLines=0;
    String nextLine;
    boolean needStart=true;
    boolean needEnds=true;
    while ((nextLine=rdr.readLine()) != null) {
      int num=countQuotes(nextLine);
      if (num % 2 == 1) {
        if (!needStart) {
          needEnds=false;
        }
 else {
          needStart=false;
        }
      }
 else {
        if (needEnds && needStart) {
          needEnds=false;
          needStart=false;
        }
      }
      byte[] bytes=(nextLine + "String_Node_Str").getBytes("String_Node_Str");
      if (currentBytes + bytes.length > maxBytesPerBatch || currentLines > maxRowsPerBatch) {
        createBatch(tmpOut,tmpFile,batchInfos);
        currentBytes=0;
        currentLines=0;
      }
      if (currentBytes == 0) {
        tmpOut=new FileOutputStream(tmpFile);
        tmpOut.write(headerBytes);
        currentBytes=headerBytesLength;
        currentLines=1;
      }
      tmpOut.write(bytes);
      currentBytes+=bytes.length;
      if (!needStart && !needEnds) {
        currentLines++;
        needStart=true;
        needEnds=true;
      }
    }
    rdr.close();
    if (currentLines > 1) {
      createBatch(tmpOut,tmpFile,batchInfos);
    }
  }
  finally {
    tmpFile.delete();
  }
  return batchInfos;
}

Fixed version (ground truth):
private List<BatchInfo> createBatchesFromCSVFile() throws IOException, AsyncApiException, ConnectionException {
  List<BatchInfo> batchInfos=new ArrayList<BatchInfo>();
  BufferedReader rdr=new BufferedReader(new InputStreamReader(new FileInputStream(bulkFileName),FILE_ENCODING));
  byte[] headerBytes=(rdr.readLine() + "String_Node_Str").getBytes("String_Node_Str");
  int headerBytesLength=headerBytes.length;
  File tmpFile=File.createTempFile("String_Node_Str","String_Node_Str");
  try {
    FileOutputStream tmpOut=new FileOutputStream(tmpFile);
    int currentBytes=0;
    int currentLines=0;
    String nextLine;
    boolean needStart=true;
    boolean needEnds=true;
    while ((nextLine=rdr.readLine()) != null) {
      int num=countQuotes(nextLine);
      if (num % 2 == 1) {
        if (!needStart) {
          needEnds=false;
        }
 else {
          needStart=false;
        }
      }
 else {
        if (needEnds && needStart) {
          needEnds=false;
          needStart=false;
        }
      }
      byte[] bytes=(nextLine + "String_Node_Str").getBytes("String_Node_Str");
      if (currentBytes + bytes.length > maxBytesPerBatch || currentLines > maxRowsPerBatch) {
        createBatch(tmpOut,tmpFile,batchInfos);
        currentBytes=0;
        currentLines=0;
      }
      if (currentBytes == 0) {
        tmpOut=new FileOutputStream(tmpFile);
        tmpOut.write(headerBytes);
        currentBytes=headerBytesLength;
        currentLines=1;
      }
      tmpOut.write(bytes);
      currentBytes+=bytes.length;
      if (!needStart && !needEnds) {
        currentLines++;
        needStart=true;
        needEnds=true;
      }
    }
    rdr.close();
    if (currentLines > 1) {
      createBatch(tmpOut,tmpFile,batchInfos);
    }
  }
  finally {
    tmpFile.delete();
  }
  return batchInfos;
}