Program: 158688
Project: 158688
Buggy source:
@Override public void run(){
  StringBuilder filePath=new StringBuilder();
  File temporaryFile=null;
  TFile outputFile=null;
  try {
    filePath.append(Constants.IO.imageBaseDir);
    filePath.append(card.hashCode()).append("String_Node_Str").append(card.getName().replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str")).append("String_Node_Str");
    temporaryFile=new File(filePath.toString());
    String imagePath=CardImageUtils.generateImagePath(card);
    outputFile=new TFile(imagePath);
    if (!outputFile.exists()) {
      outputFile.getParentFile().mkdirs();
    }
    File existingFile=new File(imagePath.replaceFirst("String_Node_Str","String_Node_Str"));
    if (existingFile.exists()) {
      new TFile(existingFile).cp_rp(outputFile);
synchronized (sync) {
        update(cardIndex + 1,count);
      }
      existingFile.delete();
      File parent=existingFile.getParentFile();
      if (parent != null && parent.isDirectory() && parent.list().length == 0) {
        parent.delete();
      }
      return;
    }
    BufferedOutputStream out;
    URLConnection httpConn=url.openConnection(p);
    httpConn.connect();
    int responseCode=((HttpURLConnection)httpConn).getResponseCode();
    if (responseCode == 200) {
      try (BufferedInputStream in=new BufferedInputStream(((HttpURLConnection)httpConn).getInputStream())){
        out=new BufferedOutputStream(new TFileOutputStream(temporaryFile));
        byte[] buf=new byte[1024];
        int len;
        while ((len=in.read(buf)) != -1) {
          if (cancel) {
            in.close();
            out.flush();
            out.close();
            temporaryFile.delete();
            return;
          }
          out.write(buf,0,len);
        }
      }
       out.flush();
      out.close();
      if (card.isTwoFacedCard()) {
        BufferedImage image=ImageIO.read(temporaryFile);
        if (image.getHeight() == 470) {
          BufferedImage renderedImage=new BufferedImage(265,370,BufferedImage.TYPE_INT_RGB);
          renderedImage.getGraphics();
          Graphics2D graphics2D=renderedImage.createGraphics();
          if (card.isTwoFacedCard() && card.isSecondSide()) {
            graphics2D.drawImage(image,0,0,265,370,313,62,578,432,null);
          }
 else {
            graphics2D.drawImage(image,0,0,265,370,41,62,306,432,null);
          }
          graphics2D.dispose();
          writeImageToFile(renderedImage,outputFile);
        }
 else {
          new TFile(temporaryFile).cp_rp(outputFile);
        }
        temporaryFile.delete();
      }
 else {
        new TFile(temporaryFile).cp_rp(outputFile);
      }
    }
 else {
      logger.warn("String_Node_Str" + card.getName() + "String_Node_Str"+ card.getSet()+ "String_Node_Str"+ responseCode+ "String_Node_Str"+ url.toString());
      if (logger.isDebugEnabled()) {
        logger.debug("String_Node_Str" + convertStreamToString(((HttpURLConnection)httpConn).getErrorStream()));
      }
    }
  }
 catch (  AccessDeniedException e) {
    logger.error("String_Node_Str" + (outputFile != null ? outputFile.toString() : "String_Node_Str" + card.getName() + "String_Node_Str"+ card.getSet()+ "String_Node_Str") + "String_Node_Str");
  }
catch (  Exception e) {
    logger.error(e,e);
  }
 finally {
    if (temporaryFile != null) {
      temporaryFile.delete();
    }
  }
synchronized (sync) {
    update(cardIndex + 1,count);
  }
}

Fixed version (ground truth):
@Override public void run(){
  StringBuilder filePath=new StringBuilder();
  File temporaryFile=null;
  TFile outputFile=null;
  try {
    filePath.append(Constants.IO.imageBaseDir);
    filePath.append(card.hashCode()).append("String_Node_Str").append(card.getName().replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str")).append("String_Node_Str");
    temporaryFile=new File(filePath.toString());
    String imagePath=CardImageUtils.generateImagePath(card);
    outputFile=new TFile(imagePath);
    if (!outputFile.exists()) {
      outputFile.getParentFile().mkdirs();
    }
    File existingFile=new File(imagePath.replaceFirst("String_Node_Str","String_Node_Str"));
    if (existingFile.exists()) {
      new TFile(existingFile).cp_rp(outputFile);
synchronized (sync) {
        update(cardIndex + 1,count);
      }
      existingFile.delete();
      File parent=existingFile.getParentFile();
      if (parent != null && parent.isDirectory() && parent.list().length == 0) {
        parent.delete();
      }
      return;
    }
    BufferedOutputStream out;
    URLConnection httpConn=url.openConnection(p);
    httpConn.connect();
    int responseCode=((HttpURLConnection)httpConn).getResponseCode();
    if (responseCode == 200) {
      try (BufferedInputStream in=new BufferedInputStream(((HttpURLConnection)httpConn).getInputStream())){
        out=new BufferedOutputStream(new TFileOutputStream(temporaryFile));
        byte[] buf=new byte[1024];
        int len;
        while ((len=in.read(buf)) != -1) {
          if (cancel) {
            in.close();
            out.flush();
            out.close();
            temporaryFile.delete();
            return;
          }
          out.write(buf,0,len);
        }
      }
       out.flush();
      out.close();
      if (card.isTwoFacedCard()) {
        BufferedImage image=ImageIO.read(temporaryFile);
        if (image.getHeight() == 470) {
          BufferedImage renderedImage=new BufferedImage(265,370,BufferedImage.TYPE_INT_RGB);
          renderedImage.getGraphics();
          Graphics2D graphics2D=renderedImage.createGraphics();
          if (card.isTwoFacedCard() && card.isSecondSide()) {
            graphics2D.drawImage(image,0,0,265,370,313,62,578,432,null);
          }
 else {
            graphics2D.drawImage(image,0,0,265,370,41,62,306,432,null);
          }
          graphics2D.dispose();
          writeImageToFile(renderedImage,outputFile);
        }
 else {
          new TFile(temporaryFile).cp_rp(outputFile);
        }
        temporaryFile.delete();
      }
 else {
        new TFile(temporaryFile).cp_rp(outputFile);
      }
    }
 else {
      logger.warn("String_Node_Str" + card.getName() + (!card.getDownloadName().equals(card.getName()) ? "String_Node_Str" + card.getDownloadName() : "String_Node_Str")+ "String_Node_Str"+ card.getSet()+ "String_Node_Str"+ responseCode+ "String_Node_Str"+ url.toString());
      if (logger.isDebugEnabled()) {
        logger.debug("String_Node_Str" + convertStreamToString(((HttpURLConnection)httpConn).getErrorStream()));
      }
    }
  }
 catch (  AccessDeniedException e) {
    logger.error("String_Node_Str" + (outputFile != null ? outputFile.toString() : "String_Node_Str" + card.getName() + "String_Node_Str"+ card.getSet()+ "String_Node_Str") + "String_Node_Str");
  }
catch (  Exception e) {
    logger.error(e,e);
  }
 finally {
    if (temporaryFile != null) {
      temporaryFile.delete();
    }
  }
synchronized (sync) {
    update(cardIndex + 1,count);
  }
}