Program: 31951
Project: 31951
Buggy source:
@Override protected Void doInBackground(Integer... params){
  MatrixError defaultError=new MatrixError();
  defaultError.errcode=MatrixError.UNKNOWN;
  try {
    URL url=new URL(mUrl);
    Log.d(LOG_TAG,"String_Node_Str" + this + "String_Node_Str");
    mDownloadStats=new IMXMediaDownloadListener.DownloadStats();
    mDownloadStats.mEstimatedRemainingTime=-1;
    InputStream stream=null;
    int filelen=-1;
    HttpURLConnection connection=null;
    try {
      connection=(HttpURLConnection)url.openConnection();
      if (mHsConfig != null && connection instanceof HttpsURLConnection) {
        HttpsURLConnection sslConn=(HttpsURLConnection)connection;
        try {
          Pair<SSLSocketFactory,X509TrustManager> pair=CertUtil.newPinnedSSLSocketFactory(mHsConfig);
          sslConn.setSSLSocketFactory(pair.first);
          sslConn.setHostnameVerifier(CertUtil.newHostnameVerifier(mHsConfig));
        }
 catch (        Exception e) {
          Log.e(LOG_TAG,"String_Node_Str" + e.getMessage());
        }
      }
      float scale=(null != mNetworkConnectivityReceiver) ? mNetworkConnectivityReceiver.getTimeoutScale() : 1.0f;
      connection.setReadTimeout((int)(DOWNLOAD_TIME_OUT * scale));
      if (mIsAvScannerEnabled && null != mEncryptedFileInfo) {
        connection.setRequestMethod("String_Node_Str");
        try {
          ObjectOutputStream body=new ObjectOutputStream(connection.getOutputStream());
          body.writeObject(mEncryptedFileInfo);
          body.close();
        }
 catch (        Exception e) {
          Log.e(LOG_TAG,"String_Node_Str" + e.getMessage());
        }
      }
      filelen=connection.getContentLength();
      stream=connection.getInputStream();
    }
 catch (    Exception e) {
      Log.e(LOG_TAG,"String_Node_Str" + e.getMessage());
      defaultError.error=e.getLocalizedMessage();
      InputStream errorStream=((HttpsURLConnection)connection).getErrorStream();
      if (null != errorStream) {
        try {
          BufferedReader streamReader=new BufferedReader(new InputStreamReader(errorStream,"String_Node_Str"));
          StringBuilder responseStrBuilder=new StringBuilder();
          String inputStr;
          while ((inputStr=streamReader.readLine()) != null) {
            responseStrBuilder.append(inputStr);
          }
          mErrorAsJsonElement=new JsonParser().parse(responseStrBuilder.toString());
        }
 catch (        Exception ee) {
          Log.e(LOG_TAG,"String_Node_Str" + ee.getMessage());
        }
      }
      Log.d(LOG_TAG,"String_Node_Str");
synchronized (mUnreachableUrls) {
        mUnreachableUrls.add(mUrl);
      }
    }
    dispatchDownloadStart();
    if ((null == stream) && (null == mErrorAsJsonElement)) {
      mErrorAsJsonElement=new JsonParser().parse("String_Node_Str" + mUrl);
synchronized (mUnreachableUrls) {
        mUnreachableUrls.add(mUrl);
      }
    }
    if (!isDownloadCancelled() && (null == mErrorAsJsonElement)) {
      final long startDownloadTime=System.currentTimeMillis();
      String filename=MXMediaDownloadWorkerTask.buildFileName(mDownloadId,mMimeType) + "String_Node_Str";
      FileOutputStream fos=new FileOutputStream(new File(mDirectoryFile,filename));
      mDownloadStats.mDownloadId=mUrl;
      mDownloadStats.mProgress=0;
      mDownloadStats.mDownloadedSize=0;
      mDownloadStats.mFileSize=filelen;
      mDownloadStats.mElapsedTime=0;
      mDownloadStats.mEstimatedRemainingTime=-1;
      mDownloadStats.mBitRate=0;
      final android.os.Handler uiHandler=new android.os.Handler(Looper.getMainLooper());
      final Timer refreshTimer=new Timer();
      uiHandler.post(new Runnable(){
        @Override public void run(){
          try {
            refreshTimer.scheduleAtFixedRate(new TimerTask(){
              @Override public void run(){
                uiHandler.post(new Runnable(){
                  @Override public void run(){
                    if (!mIsDone) {
                      publishProgress(startDownloadTime);
                    }
                  }
                }
);
              }
            }
,new java.util.Date(),100);
          }
 catch (          Throwable throwable) {
            Log.e(LOG_TAG,"String_Node_Str" + throwable.getMessage());
          }
        }
      }
);
      try {
        byte[] buf=new byte[DOWNLOAD_BUFFER_READ_SIZE];
        int len;
        while (!isDownloadCancelled() && (len=stream.read(buf)) != -1) {
          fos.write(buf,0,len);
          mDownloadStats.mDownloadedSize+=len;
        }
        if (!isDownloadCancelled()) {
          mDownloadStats.mProgress=100;
        }
      }
 catch (      OutOfMemoryError outOfMemoryError) {
        Log.e(LOG_TAG,"String_Node_Str");
        defaultError.error=outOfMemoryError.getLocalizedMessage();
      }
catch (      Exception e) {
        Log.e(LOG_TAG,"String_Node_Str" + e.getMessage());
        defaultError.error=e.getLocalizedMessage();
      }
      mIsDone=true;
      close(stream);
      fos.flush();
      fos.close();
      uiHandler.post(new Runnable(){
        @Override public void run(){
          refreshTimer.cancel();
        }
      }
);
      if ((null != connection) && (connection instanceof HttpsURLConnection)) {
        ((HttpsURLConnection)connection).disconnect();
      }
      if (mDownloadStats.mProgress == 100) {
        try {
          File originalFile=new File(mDirectoryFile,filename);
          String newFileName=MXMediaDownloadWorkerTask.buildFileName(mDownloadId,mMimeType);
          File newFile=new File(mDirectoryFile,newFileName);
          if (newFile.exists()) {
            mApplicationContext.deleteFile(newFileName);
          }
          originalFile.renameTo(newFile);
        }
 catch (        Exception e) {
          Log.e(LOG_TAG,"String_Node_Str" + e.getMessage());
          defaultError.error=e.getLocalizedMessage();
        }
      }
    }
    if (mDownloadStats.mProgress == 100) {
      Log.d(LOG_TAG,"String_Node_Str" + this + "String_Node_Str");
    }
 else {
      if (null != mErrorAsJsonElement) {
        Log.d(LOG_TAG,"String_Node_Str" + this + "String_Node_Str"+ mErrorAsJsonElement.toString());
      }
 else {
        Log.d(LOG_TAG,"String_Node_Str" + this + "String_Node_Str");
      }
    }
  }
 catch (  Exception e) {
    Log.e(LOG_TAG,"String_Node_Str" + this);
    defaultError.error=e.getMessage();
  }
  if (!TextUtils.isEmpty(defaultError.error)) {
    mErrorAsJsonElement=JsonUtils.getGson(false).toJsonTree(defaultError);
  }
synchronized (mPendingDownloadById) {
    mPendingDownloadById.remove(mDownloadId);
  }
  return null;
}

Fixed version (ground truth):
@Override protected Void doInBackground(Integer... params){
  MatrixError defaultError=new MatrixError();
  defaultError.errcode=MatrixError.UNKNOWN;
  try {
    URL url=new URL(mUrl);
    Log.d(LOG_TAG,"String_Node_Str" + this + "String_Node_Str");
    mDownloadStats=new IMXMediaDownloadListener.DownloadStats();
    mDownloadStats.mEstimatedRemainingTime=-1;
    InputStream stream=null;
    int filelen=-1;
    HttpURLConnection connection=null;
    try {
      connection=(HttpURLConnection)url.openConnection();
      if (mHsConfig != null && connection instanceof HttpsURLConnection) {
        HttpsURLConnection sslConn=(HttpsURLConnection)connection;
        try {
          Pair<SSLSocketFactory,X509TrustManager> pair=CertUtil.newPinnedSSLSocketFactory(mHsConfig);
          sslConn.setSSLSocketFactory(pair.first);
          sslConn.setHostnameVerifier(CertUtil.newHostnameVerifier(mHsConfig));
        }
 catch (        Exception e) {
          Log.e(LOG_TAG,"String_Node_Str" + e.getMessage());
        }
      }
      float scale=(null != mNetworkConnectivityReceiver) ? mNetworkConnectivityReceiver.getTimeoutScale() : 1.0f;
      connection.setReadTimeout((int)(DOWNLOAD_TIME_OUT * scale));
      if (mIsAvScannerEnabled && null != mEncryptedFileInfo) {
        connection.setRequestMethod("String_Node_Str");
        try {
          ObjectOutputStream body=new ObjectOutputStream(connection.getOutputStream());
          body.writeObject(mEncryptedFileInfo);
          body.close();
        }
 catch (        Exception e) {
          Log.e(LOG_TAG,"String_Node_Str" + e.getMessage());
        }
      }
      filelen=connection.getContentLength();
      stream=connection.getInputStream();
    }
 catch (    Exception e) {
      Log.e(LOG_TAG,"String_Node_Str" + e.getMessage());
      defaultError.error=e.getLocalizedMessage();
      InputStream errorStream=connection.getErrorStream();
      if (null != errorStream) {
        try {
          BufferedReader streamReader=new BufferedReader(new InputStreamReader(errorStream,"String_Node_Str"));
          StringBuilder responseStrBuilder=new StringBuilder();
          String inputStr;
          while ((inputStr=streamReader.readLine()) != null) {
            responseStrBuilder.append(inputStr);
          }
          mErrorAsJsonElement=new JsonParser().parse(responseStrBuilder.toString());
        }
 catch (        Exception ee) {
          Log.e(LOG_TAG,"String_Node_Str" + ee.getMessage());
        }
      }
      Log.d(LOG_TAG,"String_Node_Str");
synchronized (mUnreachableUrls) {
        mUnreachableUrls.add(mUrl);
      }
    }
    dispatchDownloadStart();
    if ((null == stream) && (null == mErrorAsJsonElement)) {
      mErrorAsJsonElement=new JsonParser().parse("String_Node_Str" + mUrl);
synchronized (mUnreachableUrls) {
        mUnreachableUrls.add(mUrl);
      }
    }
    if (!isDownloadCancelled() && (null == mErrorAsJsonElement)) {
      final long startDownloadTime=System.currentTimeMillis();
      String filename=MXMediaDownloadWorkerTask.buildFileName(mDownloadId,mMimeType) + "String_Node_Str";
      FileOutputStream fos=new FileOutputStream(new File(mDirectoryFile,filename));
      mDownloadStats.mDownloadId=mUrl;
      mDownloadStats.mProgress=0;
      mDownloadStats.mDownloadedSize=0;
      mDownloadStats.mFileSize=filelen;
      mDownloadStats.mElapsedTime=0;
      mDownloadStats.mEstimatedRemainingTime=-1;
      mDownloadStats.mBitRate=0;
      final android.os.Handler uiHandler=new android.os.Handler(Looper.getMainLooper());
      final Timer refreshTimer=new Timer();
      uiHandler.post(new Runnable(){
        @Override public void run(){
          try {
            refreshTimer.scheduleAtFixedRate(new TimerTask(){
              @Override public void run(){
                uiHandler.post(new Runnable(){
                  @Override public void run(){
                    if (!mIsDone) {
                      publishProgress(startDownloadTime);
                    }
                  }
                }
);
              }
            }
,new java.util.Date(),100);
          }
 catch (          Throwable throwable) {
            Log.e(LOG_TAG,"String_Node_Str" + throwable.getMessage());
          }
        }
      }
);
      try {
        byte[] buf=new byte[DOWNLOAD_BUFFER_READ_SIZE];
        int len;
        while (!isDownloadCancelled() && (len=stream.read(buf)) != -1) {
          fos.write(buf,0,len);
          mDownloadStats.mDownloadedSize+=len;
        }
        if (!isDownloadCancelled()) {
          mDownloadStats.mProgress=100;
        }
      }
 catch (      OutOfMemoryError outOfMemoryError) {
        Log.e(LOG_TAG,"String_Node_Str");
        defaultError.error=outOfMemoryError.getLocalizedMessage();
      }
catch (      Exception e) {
        Log.e(LOG_TAG,"String_Node_Str" + e.getMessage());
        defaultError.error=e.getLocalizedMessage();
      }
      mIsDone=true;
      close(stream);
      fos.flush();
      fos.close();
      uiHandler.post(new Runnable(){
        @Override public void run(){
          refreshTimer.cancel();
        }
      }
);
      if ((null != connection) && (connection instanceof HttpsURLConnection)) {
        ((HttpsURLConnection)connection).disconnect();
      }
      if (mDownloadStats.mProgress == 100) {
        try {
          File originalFile=new File(mDirectoryFile,filename);
          String newFileName=MXMediaDownloadWorkerTask.buildFileName(mDownloadId,mMimeType);
          File newFile=new File(mDirectoryFile,newFileName);
          if (newFile.exists()) {
            mApplicationContext.deleteFile(newFileName);
          }
          originalFile.renameTo(newFile);
        }
 catch (        Exception e) {
          Log.e(LOG_TAG,"String_Node_Str" + e.getMessage());
          defaultError.error=e.getLocalizedMessage();
        }
      }
    }
    if (mDownloadStats.mProgress == 100) {
      Log.d(LOG_TAG,"String_Node_Str" + this + "String_Node_Str");
    }
 else {
      if (null != mErrorAsJsonElement) {
        Log.d(LOG_TAG,"String_Node_Str" + this + "String_Node_Str"+ mErrorAsJsonElement.toString());
      }
 else {
        Log.d(LOG_TAG,"String_Node_Str" + this + "String_Node_Str");
      }
    }
  }
 catch (  Exception e) {
    Log.e(LOG_TAG,"String_Node_Str" + this);
    defaultError.error=e.getMessage();
  }
  if (!TextUtils.isEmpty(defaultError.error)) {
    mErrorAsJsonElement=JsonUtils.getGson(false).toJsonTree(defaultError);
  }
synchronized (mPendingDownloadById) {
    mPendingDownloadById.remove(mDownloadId);
  }
  return null;
}