Program: 10113
Project: 10113
Buggy source:
public void insertMedia(MediaPost h,Board source,boolean preview) throws ContentGetException, ContentStoreException {
  if ((preview && h.getPreview() == null) || (!preview && h.getMedia() == null))   return;
  Media mediaRow;
  try {
    mediaRow=db.getMedia(h);
  }
 catch (  DBConnectionException e) {
    throw new ContentStoreException("String_Node_Str",e);
  }
  if (mediaRow.getBanned() == 1)   return;
  String filename;
  if (this.useOldDirectoryStructure)   filename=preview ? h.getPreview() : h.getMedia();
 else   filename=preview ? (h.isOp() ? mediaRow.getPreviewOp() : mediaRow.getPreviewReply()) : mediaRow.getMedia();
  if (filename == null)   return;
  String outputDir;
  if (this.useOldDirectoryStructure)   outputDir=makeDir(h,preview ? DIR_THUMB : DIR_MEDIA,FULL_FILE);
 else   outputDir=makeDir(filename,preview ? DIR_THUMB : DIR_MEDIA,FULL_FILE);
  File outputFile=new File(outputDir + "String_Node_Str" + filename);
  if (outputFile.exists()) {
    if (preview == false)     outputFile.setLastModified(System.currentTimeMillis());
    return;
  }
  String tempFilePath;
  if (this.useOldDirectoryStructure)   tempFilePath=makeDir(h,preview ? DIR_THUMB : DIR_MEDIA,TEMP_FILE);
 else   tempFilePath=makeDir(filename,preview ? DIR_THUMB : DIR_MEDIA,TEMP_FILE);
  File tempFile=new File(tempFilePath + "String_Node_Str" + filename);
  if (tempFile.exists())   return;
  InputStream inStream=preview ? source.getMediaPreview(h) : source.getMedia(h);
  OutputStream outFile=null;
  try {
    outFile=new BufferedOutputStream(new FileOutputStream(tempFile));
    ByteStreams.copy(inStream,outFile);
  }
 catch (  FileNotFoundException e) {
    throw new ContentStoreException("String_Node_Str",e);
  }
catch (  IOException e) {
    if (!tempFile.delete())     throw new ContentStoreException("String_Node_Str" + tempFilePath + "String_Node_Str",e);
    throw new ContentStoreException("String_Node_Str",e);
  }
 finally {
    try {
      if (outFile != null)       outFile.close();
      inStream.close();
    }
 catch (    IOException e) {
      throw new ContentStoreException("String_Node_Str",e);
    }
  }
  if (!tempFile.renameTo(outputFile))   throw new ContentStoreException("String_Node_Str" + tempFilePath + "String_Node_Str");
  try {
    if (this.webGroupId != 0) {
      posix.chmod(outputFile.getCanonicalPath(),0664);
      posix.chown(outputFile.getCanonicalPath(),-1,this.webGroupId);
    }
  }
 catch (  IOException e) {
    throw new ContentStoreException("String_Node_Str",e);
  }
}

Fixed version (ground truth):
public void insertMedia(MediaPost h,Board source,boolean preview) throws ContentGetException, ContentStoreException {
  if ((preview && h.getPreview() == null) || (!preview && h.getMedia() == null))   return;
  Media mediaRow;
  try {
    mediaRow=db.getMedia(h);
  }
 catch (  DBConnectionException e) {
    throw new ContentStoreException("String_Node_Str",e);
  }
  if (mediaRow.getBanned() == 1)   return;
  String filename;
  if (this.useOldDirectoryStructure)   filename=preview ? h.getPreview() : h.getMedia();
 else   filename=preview ? (h.isOp() ? mediaRow.getPreviewOp() : mediaRow.getPreviewReply()) : mediaRow.getMedia();
  if (filename == null)   return;
  String outputDir;
  if (this.useOldDirectoryStructure)   outputDir=makeDir(h,preview ? DIR_THUMB : DIR_MEDIA,FULL_FILE);
 else   outputDir=makeDir(filename,preview ? DIR_THUMB : DIR_MEDIA,FULL_FILE);
  File outputFile=new File(outputDir + "String_Node_Str" + filename);
  if (outputFile.exists()) {
    if (preview == false)     outputFile.setLastModified(System.currentTimeMillis());
    return;
  }
  String tempFilePath;
  if (this.useOldDirectoryStructure)   tempFilePath=makeDir(h,preview ? DIR_THUMB : DIR_MEDIA,TEMP_FILE);
 else   tempFilePath=makeDir(filename,preview ? DIR_THUMB : DIR_MEDIA,TEMP_FILE);
  File tempFile=new File(tempFilePath + "String_Node_Str" + filename);
  if (tempFile.exists())   return;
  InputStream inStream=preview ? source.getMediaPreview(h) : source.getMedia(h);
  OutputStream outFile=null;
  try {
    outFile=new BufferedOutputStream(new FileOutputStream(tempFile));
    ByteStreams.copy(inStream,outFile);
  }
 catch (  FileNotFoundException e) {
    throw new ContentStoreException("String_Node_Str",e);
  }
catch (  IOException e) {
    if (!tempFile.delete())     throw new ContentStoreException("String_Node_Str" + tempFilePath + "String_Node_Str"+ filename+ "String_Node_Str",e);
    throw new ContentStoreException("String_Node_Str",e);
  }
 finally {
    try {
      if (outFile != null)       outFile.close();
      inStream.close();
    }
 catch (    IOException e) {
      throw new ContentStoreException("String_Node_Str",e);
    }
  }
  if (!tempFile.renameTo(outputFile))   throw new ContentStoreException("String_Node_Str" + tempFilePath + "String_Node_Str"+ filename+ "String_Node_Str");
  try {
    if (this.webGroupId != 0) {
      posix.chmod(outputFile.getCanonicalPath(),0664);
      posix.chown(outputFile.getCanonicalPath(),-1,this.webGroupId);
    }
  }
 catch (  IOException e) {
    throw new ContentStoreException("String_Node_Str",e);
  }
}