Program: 21374
Project: 21374
Buggy source:
public boolean download(DownloadLink downloadLink,URLConnection urlConnection,int bytesToLoad,int resumeAt){
  File fileOutput=new File(downloadLink.getFileOutput() + "String_Node_Str");
  if (fileOutput == null || fileOutput.getParentFile() == null)   return false;
  if (!fileOutput.getParentFile().exists()) {
    fileOutput.getParentFile().mkdirs();
  }
  downloadLink.setStatus(DownloadLink.STATUS_DOWNLOAD_IN_PROGRESS);
  long downloadedBytes=0;
  long start, end, time;
  try {
    int maxspeed=downloadLink.getMaximalspeed();
    ByteBuffer buffer=ByteBuffer.allocateDirect(maxspeed);
    FileOutputStream fos=new FileOutputStream(fileOutput,true);
    urlConnection.setReadTimeout(getReadTimeoutFromConfiguration());
    urlConnection.setConnectTimeout(getConnectTimeoutFromConfiguration());
    ReadableByteChannel source=Channels.newChannel(urlConnection.getInputStream());
    WritableByteChannel dest=fos.getChannel();
    String range=urlConnection.getHeaderField("String_Node_Str");
    if (range == null || bytesToLoad > 0) {
      logger.severe("String_Node_Str");
      source.close();
      dest.close();
      fos.close();
      return download(downloadLink,urlConnection,bytesToLoad);
    }
    range="String_Node_Str" + range + "String_Node_Str";
    logger.info(range);
    String[] dat=Plugin.getSimpleMatches(range,"String_Node_Str");
    int contentLen=Integer.parseInt(dat[2]);
    int startAt=Integer.parseInt(dat[0]);
    downloadedBytes=startAt;
    downloadLink.setDownloadMax(contentLen);
    downloadLink.setDownloadCurrent(startAt);
    logger.info("String_Node_Str");
    start=System.currentTimeMillis();
    buffer.clear();
    long bytesPerSecond=0;
    long deltaTime=0L;
    long timer=-System.currentTimeMillis();
    while (!aborted && !downloadLink.isAborted()) {
      if (maxspeed != (maxspeed=downloadLink.getMaximalspeed())) {
        buffer=ByteBuffer.allocateDirect(downloadLink.getMaximalspeed());
        buffer.clear();
      }
      int bytes=source.read(buffer);
      Thread.sleep(25);
      if (bytes == -1)       break;
      buffer.flip();
      dest.write(buffer);
      buffer.compact();
      downloadedBytes+=bytes;
      bytesPerSecond+=bytes;
      deltaTime=timer + System.currentTimeMillis();
      if (deltaTime > 1000) {
        downloadLink.addBytes(bytesPerSecond,deltaTime);
        bytesPerSecond=0;
        deltaTime=0L;
        timer=-System.currentTimeMillis();
      }
      firePluginEvent(new PluginEvent(this,PluginEvent.PLUGIN_DATA_CHANGED,downloadLink));
      downloadLink.setDownloadCurrent(downloadedBytes);
      if (bytesToLoad > 0 && downloadedBytes >= bytesToLoad)       break;
    }
    if (downloadedBytes < contentLen) {
      logger.info(aborted + "String_Node_Str" + downloadLink.isAborted()+ "String_Node_Str"+ downloadedBytes+ "String_Node_Str"+ contentLen);
      downloadLink.setStatus(DownloadLink.STATUS_DOWNLOAD_INCOMPLETE);
      firePluginEvent(new PluginEvent(this,PluginEvent.PLUGIN_PROGRESS_FINISH,downloadLink));
      source.close();
      dest.close();
      fos.close();
      return false;
    }
    end=System.currentTimeMillis();
    time=end - start;
    source.close();
    dest.close();
    fos.close();
    if (new File(downloadLink.getFileOutput()).exists()) {
      new File(downloadLink.getFileOutput()).delete();
    }
    logger.info(new File(downloadLink.getFileOutput()).exists() + "String_Node_Str");
    logger.info(new File(downloadLink.getFileOutput()).canWrite() + "String_Node_Str");
    logger.info(fileOutput.exists() + "String_Node_Str");
    logger.info(fileOutput.canWrite() + "String_Node_Str");
    if (!fileOutput.renameTo(new File(downloadLink.getFileOutput()))) {
      logger.severe("String_Node_Str" + fileOutput + "String_Node_Str"+ downloadLink.getFileOutput());
      downloadLink.setStatus(DownloadLink.STATUS_DOWNLOAD_INCOMPLETE);
      firePluginEvent(new PluginEvent(this,PluginEvent.PLUGIN_PROGRESS_FINISH,downloadLink));
      return false;
    }
    downloadLink.setStatus(DownloadLink.STATUS_DOWNLOAD_FINISHED);
    firePluginEvent(new PluginEvent(this,PluginEvent.PLUGIN_PROGRESS_FINISH,downloadLink));
    logger.info("String_Node_Str" + fileOutput.getAbsolutePath());
    logger.info(downloadedBytes + "String_Node_Str" + time+ "String_Node_Str");
    return true;
  }
 catch (  FileNotFoundException e) {
    logger.severe("String_Node_Str" + e.getLocalizedMessage());
  }
catch (  SecurityException e) {
    logger.severe("String_Node_Str" + e.getLocalizedMessage());
  }
catch (  IOException e) {
    logger.severe("String_Node_Str" + e.getLocalizedMessage());
  }
catch (  Exception e) {
    e.printStackTrace();
  }
  firePluginEvent(new PluginEvent(this,PluginEvent.PLUGIN_PROGRESS_FINISH,downloadLink));
  downloadLink.setStatus(DownloadLink.STATUS_DOWNLOAD_INCOMPLETE);
  return false;
}

Fixed version (ground truth):
public boolean download(DownloadLink downloadLink,URLConnection urlConnection,int bytesToLoad,int resumeAt){
  File fileOutput=new File(downloadLink.getFileOutput() + "String_Node_Str");
  if (fileOutput == null || fileOutput.getParentFile() == null)   return false;
  if (!fileOutput.getParentFile().exists()) {
    fileOutput.getParentFile().mkdirs();
  }
  downloadLink.setStatus(DownloadLink.STATUS_DOWNLOAD_IN_PROGRESS);
  long downloadedBytes=0;
  long start, end, time;
  try {
    int maxspeed=downloadLink.getMaximalspeed();
    ByteBuffer buffer=ByteBuffer.allocateDirect(maxspeed);
    FileOutputStream fos=new FileOutputStream(fileOutput,true);
    urlConnection.setReadTimeout(getReadTimeoutFromConfiguration());
    urlConnection.setConnectTimeout(getConnectTimeoutFromConfiguration());
    ReadableByteChannel source=Channels.newChannel(urlConnection.getInputStream());
    WritableByteChannel dest=fos.getChannel();
    String range=urlConnection.getHeaderField("String_Node_Str");
    if (range == null || bytesToLoad > 0) {
      logger.severe("String_Node_Str");
      source.close();
      dest.close();
      fos.close();
      return download(downloadLink,urlConnection,bytesToLoad);
    }
    range="String_Node_Str" + range + "String_Node_Str";
    logger.info(range);
    String[] dat=Plugin.getSimpleMatches(range,"String_Node_Str");
    int contentLen=Integer.parseInt(dat[2]);
    int startAt=Integer.parseInt(dat[0]);
    downloadedBytes=startAt;
    downloadLink.setDownloadMax(contentLen);
    downloadLink.setDownloadCurrent(startAt);
    logger.info("String_Node_Str");
    start=System.currentTimeMillis();
    buffer.clear();
    long bytesPerSecond=0;
    long deltaTime=0L;
    long timer=-System.currentTimeMillis();
    while (!aborted && !downloadLink.isAborted()) {
      int bytes=source.read(buffer);
      if (downloadLink.isLimited)       Thread.sleep(25);
      if (bytes == -1)       break;
      buffer.flip();
      dest.write(buffer);
      buffer.compact();
      downloadedBytes+=bytes;
      bytesPerSecond+=bytes;
      deltaTime=timer + System.currentTimeMillis();
      if (deltaTime > 1000) {
        downloadLink.addBytes(bytesPerSecond,deltaTime);
        bytesPerSecond=0;
        deltaTime=0L;
        timer=-System.currentTimeMillis();
        if (maxspeed != (maxspeed=downloadLink.getMaximalspeed())) {
          buffer=ByteBuffer.allocateDirect(downloadLink.getMaximalspeed());
          buffer.clear();
        }
      }
      firePluginEvent(new PluginEvent(this,PluginEvent.PLUGIN_DATA_CHANGED,downloadLink));
      downloadLink.setDownloadCurrent(downloadedBytes);
      if (bytesToLoad > 0 && downloadedBytes >= bytesToLoad)       break;
    }
    if (downloadedBytes < contentLen) {
      logger.info(aborted + "String_Node_Str" + downloadLink.isAborted()+ "String_Node_Str"+ downloadedBytes+ "String_Node_Str"+ contentLen);
      downloadLink.setStatus(DownloadLink.STATUS_DOWNLOAD_INCOMPLETE);
      firePluginEvent(new PluginEvent(this,PluginEvent.PLUGIN_PROGRESS_FINISH,downloadLink));
      source.close();
      dest.close();
      fos.close();
      return false;
    }
    end=System.currentTimeMillis();
    time=end - start;
    source.close();
    dest.close();
    fos.close();
    if (new File(downloadLink.getFileOutput()).exists()) {
      new File(downloadLink.getFileOutput()).delete();
    }
    logger.info(new File(downloadLink.getFileOutput()).exists() + "String_Node_Str");
    logger.info(new File(downloadLink.getFileOutput()).canWrite() + "String_Node_Str");
    logger.info(fileOutput.exists() + "String_Node_Str");
    logger.info(fileOutput.canWrite() + "String_Node_Str");
    if (!fileOutput.renameTo(new File(downloadLink.getFileOutput()))) {
      logger.severe("String_Node_Str" + fileOutput + "String_Node_Str"+ downloadLink.getFileOutput());
      downloadLink.setStatus(DownloadLink.STATUS_DOWNLOAD_INCOMPLETE);
      firePluginEvent(new PluginEvent(this,PluginEvent.PLUGIN_PROGRESS_FINISH,downloadLink));
      return false;
    }
    downloadLink.setStatus(DownloadLink.STATUS_DOWNLOAD_FINISHED);
    firePluginEvent(new PluginEvent(this,PluginEvent.PLUGIN_PROGRESS_FINISH,downloadLink));
    logger.info("String_Node_Str" + fileOutput.getAbsolutePath());
    logger.info(downloadedBytes + "String_Node_Str" + time+ "String_Node_Str");
    return true;
  }
 catch (  FileNotFoundException e) {
    logger.severe("String_Node_Str" + e.getLocalizedMessage());
  }
catch (  SecurityException e) {
    logger.severe("String_Node_Str" + e.getLocalizedMessage());
  }
catch (  IOException e) {
    logger.severe("String_Node_Str" + e.getLocalizedMessage());
  }
catch (  Exception e) {
    e.printStackTrace();
  }
  firePluginEvent(new PluginEvent(this,PluginEvent.PLUGIN_PROGRESS_FINISH,downloadLink));
  downloadLink.setStatus(DownloadLink.STATUS_DOWNLOAD_INCOMPLETE);
  return false;
}