Program: 5078
Project: 5078
Buggy source:
public void doDownload(){
  if (_wasShutdown)   return;
  readHeader();
  if (_state == ERROR)   return;
  SettingsManager set=SettingsManager.instance();
  _downloadDir=set.getSaveDirectory();
  String incompleteDir=set.getIncompleteDirectory();
  File myFile=new File(incompleteDir,_filename);
  String pathname=myFile.getAbsolutePath();
  File myTest=new File(_downloadDir,_filename);
  String path=myTest.getAbsolutePath();
  File f;
  String p;
  try {
    File shared=new File(_downloadDir);
    String shared_path=shared.getCanonicalPath();
    f=new File(myTest.getParent());
    p=f.getCanonicalPath();
    if (!p.equals(shared_path)) {
      _state=ERROR;
      return;
    }
  }
 catch (  Exception e) {
    _state=ERROR;
    return;
  }
  if ((myTest.exists()) && (!_resume)) {
    if (!_callback.overwriteFile(_filename)) {
      _stateString="String_Node_Str";
      _state=ERROR;
      return;
    }
  }
  try {
    _fos=new FileOutputStream(pathname,_resume);
  }
 catch (  FileNotFoundException e) {
    _state=ERROR;
    return;
  }
catch (  Exception e) {
    _state=ERROR;
    return;
  }
  int c=-1;
  byte[] buf=new byte[1024];
  while (true) {
    if (_amountRead == _sizeOfFile) {
      _state=COMPLETE;
      break;
    }
    try {
      c=_br.read(buf);
    }
 catch (    Exception e) {
      e.printStackTrace();
      _state=ERROR;
      return;
    }
    if (c == -1) {
      break;
    }
    try {
      _fos.write(buf,0,c);
    }
 catch (    Exception e) {
      _state=ERROR;
      break;
    }
    _amountRead+=c;
  }
  try {
    _br.close();
    _fos.close();
  }
 catch (  IOException e) {
    _state=ERROR;
    return;
  }
  if (_amountRead == _sizeOfFile) {
    String pname=_downloadDir + _filename;
    boolean ok=myFile.renameTo(new File(pname));
    if (!ok) {
      _state=ERROR;
      _stateString="String_Node_Str";
      return;
    }
    _state=COMPLETE;
    FileManager.getFileManager().addFileIfShared(pname);
  }
 else {
    _state=ERROR;
  }
}

Fixed version (ground truth):
public void doDownload(){
  if (_wasShutdown)   return;
  readHeader();
  if (_state == ERROR)   return;
  SettingsManager set=SettingsManager.instance();
  _downloadDir=set.getSaveDirectory();
  String incompleteDir=set.getIncompleteDirectory();
  File myFile=new File(incompleteDir,_filename);
  String pathname=myFile.getAbsolutePath();
  File myTest=new File(_downloadDir,_filename);
  String path=myTest.getAbsolutePath();
  File f;
  String p;
  try {
    File shared=new File(_downloadDir);
    String shared_path=shared.getCanonicalPath();
    f=new File(myTest.getParent());
    p=f.getCanonicalPath();
    if (!p.equals(shared_path)) {
      _state=ERROR;
      return;
    }
  }
 catch (  Exception e) {
    _state=ERROR;
    return;
  }
  if ((myTest.exists()) && (!_resume)) {
    if (!_callback.overwriteFile(_filename)) {
      _stateString="String_Node_Str";
      _state=ERROR;
      return;
    }
  }
  try {
    _fos=new FileOutputStream(pathname,_resume);
  }
 catch (  FileNotFoundException e) {
    _state=ERROR;
    return;
  }
catch (  Exception e) {
    _state=ERROR;
    return;
  }
  int c=-1;
  byte[] buf=new byte[1024];
  while (true) {
    if (_amountRead == _sizeOfFile) {
      _state=COMPLETE;
      break;
    }
    try {
      c=_br.read(buf);
    }
 catch (    Exception e) {
      _state=ERROR;
      return;
    }
    if (c == -1) {
      break;
    }
    try {
      _fos.write(buf,0,c);
    }
 catch (    Exception e) {
      _state=ERROR;
      break;
    }
    _amountRead+=c;
  }
  try {
    _br.close();
    _fos.close();
  }
 catch (  IOException e) {
    _state=ERROR;
    return;
  }
  if (_amountRead == _sizeOfFile) {
    String pname=_downloadDir + _filename;
    boolean ok=myFile.renameTo(new File(pname));
    if (!ok) {
      _state=ERROR;
      _stateString="String_Node_Str";
      return;
    }
    _state=COMPLETE;
    FileManager.getFileManager().addFileIfShared(pname);
  }
 else {
    _state=ERROR;
    _stateString="String_Node_Str";
  }
}