Program: 130577
Project: 130577
Buggy source:
/** 
 * <BR>
 * @param params Void...
 * @return Void
 * @see android.os.AsyncTask#doInBackground(Params[])
 */
@Override protected Void doInBackground(Void... params){
  createFile();
  mDownloadTask.setDownloadState(DownloadState.DOWNLOADING);
  mDlTaskMng.updateDownloadTask(mDownloadTask);
  for (  DownloadListener l : mDlTaskMng.getListeners(mDownloadTask)) {
    l.onDownloadStart();
  }
  HttpURLConnection conn=null;
  RandomAccessFile accessFile=null;
  InputStream is=null;
  long finishedSize=0;
  long totalSize=0;
  long startSize=0;
  try {
    URL url=new URL(mDownloadTask.getUrl());
    conn=(HttpURLConnection)url.openConnection();
    conn.setConnectTimeout(5000);
    conn.setRequestProperty("String_Node_Str","String_Node_Str");
    conn.setRequestMethod("String_Node_Str");
    conn.setRequestProperty("String_Node_Str","String_Node_Str" + mDownloadTask.getFinishedSize() + "String_Node_Str"+ mDownloadTask.getTotalSize());
    conn.setRequestProperty("String_Node_Str","String_Node_Str");
    accessFile=new RandomAccessFile(mDownloadTask.getFilePath() + "String_Node_Str" + mDownloadTask.getFileName(),"String_Node_Str");
    accessFile.seek(mDownloadTask.getFinishedSize());
    finishedSize=mDownloadTask.getFinishedSize();
    totalSize=mDownloadTask.getTotalSize();
    startSize=finishedSize;
    is=conn.getInputStream();
    Log.d(TAG,"String_Node_Str" + mDlTaskMng.getListeners(mDownloadTask).size());
    Log.i(TAG,"String_Node_Str");
    byte[] buffer=new byte[BUFFER_SIZE];
    int length=-1;
    long startTime=System.currentTimeMillis();
    int speed=0;
    while ((length=is.read(buffer)) != -1) {
      if (mPause) {
        Log.i(TAG,"String_Node_Str");
        mDownloadTask.setDownloadState(DownloadState.PAUSE);
        mDownloadTask.setFinishedSize(finishedSize);
        for (        DownloadListener l : mDlTaskMng.getListeners(mDownloadTask)) {
          l.onDownloadPause();
        }
        mDlTaskMng.updateDownloadTask(mDownloadTask);
        return null;
      }
      finishedSize+=length;
      Log.d(TAG,"String_Node_Str" + length);
      accessFile.write(buffer,0,length);
      if (finishedSize - mDownloadTask.getFinishedSize() > UPDATE_DB_PER_SIZE) {
        mDownloadTask.setFinishedSize(finishedSize);
        mDlTaskMng.updateDownloadTask(mDownloadTask);
        speed=(int)((finishedSize - startSize) / (int)(System.currentTimeMillis() + 1 - startTime));
        publishProgress((int)finishedSize / 1024,(int)totalSize / 1024,(int)speed / 1024);
      }
 else       if (totalSize - finishedSize < UPDATE_DB_PER_SIZE) {
        mDownloadTask.setFinishedSize(finishedSize);
        speed=(int)((finishedSize - startSize) / (int)(System.currentTimeMillis() + 1 - startTime));
        publishProgress((int)finishedSize / 1024,(int)totalSize / 1024,speed / 1024);
      }
    }
    conn.disconnect();
    mDownloadTask.setDownloadState(DownloadState.FINISHED);
    mDownloadTask.setFinishedSize(finishedSize);
    Log.d(TAG,"String_Node_Str" + mDownloadTask);
    mDlTaskMng.updateDownloadTask(mDownloadTask);
    for (    DownloadListener l : mDlTaskMng.getListeners(mDownloadTask)) {
      l.onDownloadFinish(mDownloadTask.getFilePath() + "String_Node_Str" + mDownloadTask.getFileName());
    }
    mDlTaskMng.getListeners(mDownloadTask).clear();
    mDlTaskMng.removeListener(mDownloadTask);
  }
 catch (  Exception e) {
    Log.e(TAG,"String_Node_Str" + e.getMessage());
    e.printStackTrace();
    mDownloadTask.setDownloadState(DownloadState.FAILED);
    mDownloadTask.setFinishedSize(finishedSize);
    for (    DownloadListener l : mDlTaskMng.getListeners(mDownloadTask)) {
      l.onDownloadFail();
    }
    mDlTaskMng.updateDownloadTask(mDownloadTask);
  }
 finally {
    try {
      if (is != null) {
        is.close();
      }
      if (accessFile != null) {
        accessFile.close();
      }
      if (conn != null) {
        conn.disconnect();
      }
    }
 catch (    Exception e) {
      e.printStackTrace();
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * <BR>
 * @param params Void...
 * @return Void
 * @see android.os.AsyncTask#doInBackground(Params[])
 */
@Override protected Void doInBackground(Void... params){
  createFile();
  mDownloadTask.setDownloadState(DownloadState.DOWNLOADING);
  mDlTaskMng.updateDownloadTask(mDownloadTask);
  for (  DownloadListener l : mDlTaskMng.getListeners(mDownloadTask)) {
    l.onDownloadStart();
  }
  HttpURLConnection conn=null;
  RandomAccessFile accessFile=null;
  InputStream is=null;
  long finishedSize=0;
  long totalSize=0;
  long startSize=0;
  try {
    URL url=new URL(mDownloadTask.getUrl());
    conn=(HttpURLConnection)url.openConnection();
    conn.setConnectTimeout(5000);
    conn.setRequestProperty("String_Node_Str","String_Node_Str");
    conn.setRequestMethod("String_Node_Str");
    conn.setRequestProperty("String_Node_Str","String_Node_Str" + mDownloadTask.getFinishedSize() + "String_Node_Str"+ mDownloadTask.getTotalSize());
    conn.setRequestProperty("String_Node_Str","String_Node_Str");
    accessFile=new RandomAccessFile(mDownloadTask.getFilePath() + "String_Node_Str" + mDownloadTask.getFileName(),"String_Node_Str");
    accessFile.seek(mDownloadTask.getFinishedSize());
    finishedSize=mDownloadTask.getFinishedSize();
    totalSize=mDownloadTask.getTotalSize();
    startSize=finishedSize;
    is=conn.getInputStream();
    Log.d(TAG,"String_Node_Str" + mDlTaskMng.getListeners(mDownloadTask).size());
    Log.i(TAG,"String_Node_Str");
    byte[] buffer=new byte[BUFFER_SIZE];
    int length=-1;
    long startTime=System.currentTimeMillis();
    int speed=0;
    while ((length=is.read(buffer)) != -1) {
      if (mPause) {
        Log.i(TAG,"String_Node_Str");
        mDownloadTask.setDownloadState(DownloadState.PAUSE);
        mDownloadTask.setFinishedSize(finishedSize);
        for (        DownloadListener l : mDlTaskMng.getListeners(mDownloadTask)) {
          l.onDownloadPause();
        }
        mDlTaskMng.updateDownloadTask(mDownloadTask);
        return null;
      }
      finishedSize+=length;
      Log.d(TAG,"String_Node_Str" + length);
      accessFile.write(buffer,0,length);
      if (finishedSize - mDownloadTask.getFinishedSize() > UPDATE_DB_PER_SIZE) {
        mDownloadTask.setFinishedSize(finishedSize);
        mDlTaskMng.updateDownloadTask(mDownloadTask);
        speed=(int)((finishedSize - startSize) / (int)(System.currentTimeMillis() + 1 - startTime));
        publishProgress((int)finishedSize,(int)totalSize,speed);
      }
 else       if (totalSize - finishedSize < UPDATE_DB_PER_SIZE) {
        mDownloadTask.setFinishedSize(finishedSize);
        speed=(int)((finishedSize - startSize) / (int)(System.currentTimeMillis() + 1 - startTime));
        publishProgress((int)finishedSize,(int)totalSize,speed);
      }
    }
    conn.disconnect();
    mDownloadTask.setDownloadState(DownloadState.FINISHED);
    mDownloadTask.setFinishedSize(finishedSize);
    Log.d(TAG,"String_Node_Str" + mDownloadTask);
    mDlTaskMng.updateDownloadTask(mDownloadTask);
    for (    DownloadListener l : mDlTaskMng.getListeners(mDownloadTask)) {
      l.onDownloadFinish(mDownloadTask.getFilePath() + "String_Node_Str" + mDownloadTask.getFileName());
    }
    mDlTaskMng.getListeners(mDownloadTask).clear();
    mDlTaskMng.removeListener(mDownloadTask);
  }
 catch (  Exception e) {
    Log.e(TAG,"String_Node_Str" + e.getMessage());
    e.printStackTrace();
    mDownloadTask.setDownloadState(DownloadState.FAILED);
    mDownloadTask.setFinishedSize(finishedSize);
    for (    DownloadListener l : mDlTaskMng.getListeners(mDownloadTask)) {
      l.onDownloadFail();
    }
    mDlTaskMng.updateDownloadTask(mDownloadTask);
  }
 finally {
    try {
      if (is != null) {
        is.close();
      }
      if (accessFile != null) {
        accessFile.close();
      }
      if (conn != null) {
        conn.disconnect();
      }
    }
 catch (    Exception e) {
      e.printStackTrace();
    }
  }
  return null;
}