Program: 189247
Project: 189247
Buggy source:
public void run(){
  try {
    byte[] buffer=new byte[4096];
    long downloaded=0;
    InputStream in=conn.getInputStream();
    outFile=new File(org.headsupdev.agile.api.util.FileUtil.getTempDir(),new File(update.getFile()).getName());
    OutputStream out=new FileOutputStream(outFile);
    int chunk;
    while ((chunk=in.read(buffer)) > -1) {
      downloaded+=chunk;
      out.write(buffer,0,chunk);
      if (length > 0) {
        int prog=(int)(((double)downloaded / length) * 100);
        if (prog > 99) {
          prog=99;
        }
        progress=prog;
      }
    }
    in.close();
    out.close();
    outFile=new TarFile(new GZipFile(outFile).expand(true)).expand();
    File tmpDir=new File(outFile.getAbsolutePath() + "String_Node_Str");
    outFile.renameTo(tmpDir);
    File[] children=tmpDir.listFiles();
    outFile=new File(outFile.getParentFile(),outFile.getName());
    children[0].renameTo(outFile);
    tmpDir.delete();
    String version=new File(update.getFile()).getName();
    version=version.substring(0,version.indexOf("String_Node_Str"));
    Event event=new SystemEvent(Manager.getStorageInstance().getGlobalConfiguration().getProductName() + "String_Node_Str" + version,Manager.getStorageInstance().getGlobalConfiguration().getProductName() + "String_Node_Str" + version+ "String_Node_Str","String_Node_Str" + Manager.getStorageInstance().getGlobalConfiguration().getProductName() + "String_Node_Str"+ version+ "String_Node_Str"+ update.getDetails());
    Manager.getStorageInstance().addEvent(event);
    Manager.getInstance().fireEventAdded(event);
    Process chmodProcess=null;
    try {
      chmodProcess=Runtime.getRuntime().exec("String_Node_Str" + new File(outFile,"String_Node_Str").getAbsolutePath());
      chmodProcess.waitFor();
    }
 catch (    InterruptedException e) {
    }
 finally {
      if (chmodProcess != null) {
        IOUtil.close(chmodProcess.getOutputStream());
        IOUtil.close(chmodProcess.getErrorStream());
        IOUtil.close(chmodProcess.getInputStream());
        chmodProcess.destroy();
      }
    }
    updateProperties(new File(new File(outFile,"String_Node_Str"),"String_Node_Str"));
    File mainDir=new File("String_Node_Str");
    File backupDir=new File(mainDir,"String_Node_Str");
    if (backupDir.exists()) {
      for (      File child : backupDir.listFiles()) {
        FileUtil.delete(child);
      }
    }
 else {
      backupDir.mkdir();
    }
    for (    File child : mainDir.listFiles()) {
      if (child.equals(outFile)) {
        continue;
      }
      child.renameTo(new File(backupDir,child.getName()));
    }
    for (    File child : outFile.listFiles()) {
      child.renameTo(new File(mainDir,child.getName()));
    }
    outFile.delete();
    progress=100;
    restartThread.start();
  }
 catch (  IOException e) {
    log.error("String_Node_Str",e);
  }
}

Fixed version (ground truth):
public void run(){
  try {
    byte[] buffer=new byte[4096];
    long downloaded=0;
    InputStream in=connection.getInputStream();
    outFile=new File(org.headsupdev.agile.api.util.FileUtil.getTempDir(),new File(update.getFile()).getName());
    OutputStream out=new FileOutputStream(outFile);
    int chunk;
    while ((chunk=in.read(buffer)) > -1) {
      downloaded+=chunk;
      out.write(buffer,0,chunk);
      if (length > 0) {
        int prog=(int)(((double)downloaded / length) * 100);
        if (prog > 99) {
          prog=99;
        }
        progress=prog;
      }
    }
    in.close();
    out.close();
    outFile=new TarFile(new GZipFile(outFile).expand(true)).expand();
    File tmpDir=new File(outFile.getAbsolutePath() + "String_Node_Str");
    outFile.renameTo(tmpDir);
    File[] children=tmpDir.listFiles();
    outFile=new File(outFile.getParentFile(),outFile.getName());
    children[0].renameTo(outFile);
    tmpDir.delete();
    String version=new File(update.getFile()).getName();
    version=version.substring(0,version.indexOf("String_Node_Str"));
    Event event=new SystemEvent(Manager.getStorageInstance().getGlobalConfiguration().getProductName() + "String_Node_Str" + version,Manager.getStorageInstance().getGlobalConfiguration().getProductName() + "String_Node_Str" + version+ "String_Node_Str","String_Node_Str" + Manager.getStorageInstance().getGlobalConfiguration().getProductName() + "String_Node_Str"+ version+ "String_Node_Str"+ update.getDetails());
    Manager.getStorageInstance().addEvent(event);
    Manager.getInstance().fireEventAdded(event);
    Process chmodProcess=null;
    try {
      chmodProcess=Runtime.getRuntime().exec("String_Node_Str" + new File(outFile,"String_Node_Str").getAbsolutePath());
      chmodProcess.waitFor();
    }
 catch (    InterruptedException e) {
    }
 finally {
      if (chmodProcess != null) {
        IOUtil.close(chmodProcess.getOutputStream());
        IOUtil.close(chmodProcess.getErrorStream());
        IOUtil.close(chmodProcess.getInputStream());
        chmodProcess.destroy();
      }
    }
    updateProperties(new File(new File(outFile,"String_Node_Str"),"String_Node_Str"));
    File mainDir=new File("String_Node_Str");
    File backupDir=new File(mainDir,"String_Node_Str");
    if (backupDir.exists()) {
      for (      File child : backupDir.listFiles()) {
        FileUtil.delete(child);
      }
    }
 else {
      backupDir.mkdir();
    }
    for (    File child : mainDir.listFiles()) {
      if (child.equals(outFile)) {
        continue;
      }
      child.renameTo(new File(backupDir,child.getName()));
    }
    for (    File child : outFile.listFiles()) {
      child.renameTo(new File(mainDir,child.getName()));
    }
    outFile.delete();
    progress=100;
    restartThread.start();
  }
 catch (  IOException e) {
    log.error("String_Node_Str",e);
  }
}