Program: 147059
Project: 147059
Buggy source:
public void doPost(HttpServletRequest req,HttpServletResponse resp) throws IOException {
  String MD5=null;
  try {
    Enumeration headers=req.getHeaderNames();
    String postData="String_Node_Str";
    long totalBytesRead=0;
    while (headers.hasMoreElements()) {
      String nextName=(String)headers.nextElement();
      String nextValue=req.getHeader(nextName);
      if (nextName.equalsIgnoreCase("String_Node_Str")) {
        resp.addHeader("String_Node_Str",nextValue);
        MD5=nextValue;
        if (md5toLastByteRead.containsKey(MD5)) {
          totalBytesRead=md5toLastByteRead.get(MD5).longValue();
        }
 else {
          md5toLastByteRead.put(MD5,new Long(0));
        }
      }
      postData+=nextName + "String_Node_Str" + nextValue+ "String_Node_Str";
    }
    int bufSize=1400;
    byte[] temp=new byte[bufSize];
    InputStream stream=req.getInputStream();
    int bytesRead=stream.read(temp);
    ByteArrayOutputStream body=new ByteArrayOutputStream();
    File f;
    if (MD5 != null) {
      f=new File(_storageRoot + MD5 + "String_Node_Str");
    }
 else     f=new File(this.getNewFileName("String_Node_Str"));
    if (!f.exists())     f.createNewFile();
    OutputStream output=new BufferedOutputStream(new FileOutputStream(f,true));
    try {
      while (bytesRead != -1) {
        totalBytesRead+=bytesRead;
        if (MD5 != null)         md5toLastByteRead.put(MD5,new Long(totalBytesRead));
        if (bytesRead < bufSize) {
          byte[] newTemp=new byte[bytesRead];
          for (int i=0; i < bytesRead; i++) {
            newTemp[i]=temp[i];
          }
          output.write(newTemp);
          body.write(newTemp);
        }
 else {
          output.write(temp);
          body.write(temp);
        }
        bytesRead=req.getInputStream().read(temp);
      }
    }
  finally {
      output.close();
    }
    if (MD5 != null) {
      String localMD5=hashcode(_storageRoot + String.valueOf(MD5) + "String_Node_Str");
      if (localMD5 != null && !MD5.equalsIgnoreCase(localMD5)) {
        return;
      }
 else {
        File g=new File(_storageRoot + String.valueOf(MD5) + "String_Node_Str");
        File h=new File(_storageRoot + String.valueOf(MD5) + "String_Node_Str");
        for (int i=1; h.exists(); i++) {
          h=new File(_storageRoot + String.valueOf(MD5) + "String_Node_Str"+ i+ "String_Node_Str");
        }
        g.renameTo(h);
        md5toLastByteRead.remove(MD5);
        body.close();
        body=new ByteArrayOutputStream();
        InputStream in=new BufferedInputStream(new FileInputStream(h));
        bufSize=8192;
        temp=new byte[bufSize];
        bytesRead=in.read(temp);
        while (bytesRead != -1) {
          if (bytesRead < bufSize) {
            byte[] newTemp=new byte[bytesRead];
            for (int i=0; i < bytesRead; i++) {
              newTemp[i]=temp[i];
            }
            body.write(newTemp);
          }
 else {
            body.write(temp);
          }
          bytesRead=in.read(temp);
        }
        body.flush();
      }
    }
    postData+="String_Node_Str" + totalBytesRead + "String_Node_Str";
    postData+=new String(body.toByteArray());
    parseAndSaveHtml(req,body.toByteArray());
    postData+=_lastPostParsable=trim(postData);
    _lastFileName=saveFile(postData);
  }
 catch (  Exception e) {
    logException(e);
    _lastError=HEADER + "String_Node_Str" + e.getMessage();
    _lastError+="String_Node_Str";
    e.printStackTrace(resp.getWriter());
  }
}

Fixed version (ground truth):
public void doPost(HttpServletRequest req,HttpServletResponse resp) throws IOException {
  String MD5=null;
  try {
    Enumeration headers=req.getHeaderNames();
    String postData="String_Node_Str";
    long totalBytesRead=0;
    while (headers.hasMoreElements()) {
      String nextName=(String)headers.nextElement();
      String nextValue=req.getHeader(nextName);
      if (nextName.equalsIgnoreCase("String_Node_Str")) {
        resp.addHeader("String_Node_Str",nextValue);
        MD5=nextValue;
        if (md5toLastByteRead.containsKey(MD5)) {
          totalBytesRead=md5toLastByteRead.get(MD5).longValue();
        }
 else {
          md5toLastByteRead.put(MD5,new Long(0));
        }
      }
      postData+=nextName + "String_Node_Str" + nextValue+ "String_Node_Str";
    }
    int bufSize=1400;
    byte[] temp=new byte[bufSize];
    ByteArrayOutputStream body=new ByteArrayOutputStream();
    File f;
    if (MD5 != null) {
      f=new File(_storageRoot + MD5 + "String_Node_Str");
    }
 else     f=new File(this.getNewFileName("String_Node_Str"));
    if (!f.exists())     f.createNewFile();
    if (!f.canWrite())     throw new IOException("String_Node_Str");
    OutputStream output=new BufferedOutputStream(new FileOutputStream(f,true));
    int bytesRead=req.getInputStream().read(temp);
    try {
      while (bytesRead != -1) {
        if (bytesRead < bufSize) {
          byte[] newTemp=new byte[bytesRead];
          for (int i=0; i < bytesRead; i++) {
            newTemp[i]=temp[i];
          }
          output.write(newTemp);
          body.write(newTemp);
        }
 else {
          output.write(temp);
          body.write(temp);
        }
        output.flush();
        totalBytesRead+=bytesRead;
        if (MD5 != null)         md5toLastByteRead.put(MD5,new Long(totalBytesRead));
        bytesRead=req.getInputStream().read(temp);
      }
    }
  finally {
      output.close();
    }
    if (MD5 != null) {
      String localMD5=hashcode(_storageRoot + String.valueOf(MD5) + "String_Node_Str");
      if (localMD5 != null && !MD5.equalsIgnoreCase(localMD5)) {
        return;
      }
 else {
        File g=new File(_storageRoot + String.valueOf(MD5) + "String_Node_Str");
        File h=new File(_storageRoot + String.valueOf(MD5) + "String_Node_Str");
        for (int i=1; h.exists(); i++) {
          h=new File(_storageRoot + String.valueOf(MD5) + "String_Node_Str"+ i+ "String_Node_Str");
        }
        g.renameTo(h);
        md5toLastByteRead.remove(MD5);
        body.close();
        body=new ByteArrayOutputStream();
        InputStream in=new BufferedInputStream(new FileInputStream(h));
        bufSize=8192;
        temp=new byte[bufSize];
        bytesRead=in.read(temp);
        while (bytesRead != -1) {
          if (bytesRead < bufSize) {
            byte[] newTemp=new byte[bytesRead];
            for (int i=0; i < bytesRead; i++) {
              newTemp[i]=temp[i];
            }
            body.write(newTemp);
          }
 else {
            body.write(temp);
          }
          bytesRead=in.read(temp);
        }
        body.flush();
      }
    }
    postData+="String_Node_Str" + totalBytesRead + "String_Node_Str";
    postData+=new String(body.toByteArray());
    parseAndSaveHtml(req,body.toByteArray());
    postData+=_lastPostParsable=trim(postData);
    _lastFileName=saveFile(postData);
  }
 catch (  Exception e) {
    logException(e);
    _lastError=HEADER + "String_Node_Str" + e.getMessage();
    _lastError+="String_Node_Str";
    e.printStackTrace(resp.getWriter());
  }
}