Program: 153154
Project: 153154
Buggy source:
private void downloadApp(String url,String mimetype,AppInfo appInfo){
  if (null == url || null == mimetype || null == appInfo) {
    throw new NullPointerException();
  }
  if (null == appInfo.mAppCode || null == appInfo.mAppVersion || null == appInfo.mAppName) {
    throw new IllegalArgumentException();
  }
  boolean bAppExistsInDb=false;
  PackageState pkgState=PackageState.unknown;
  String downloadUri=null;
  Cursor cursor=null;
  try {
    String[] columns={InstalledAppDb.COLUMN_CODE,InstalledAppDb.COLUMN_STATE,InstalledAppDb.COLUMN_DOWNLOAD_URI};
    String where=InstalledAppDb.COLUMN_CODE + "String_Node_Str";
    String[] whereValue={appInfo.mAppCode};
    cursor=getContentResolver().query(BehooProvider.INSTALLED_APP_CONTENT_URI,columns,where,whereValue,null);
    bAppExistsInDb=(cursor.getCount() == 1);
    cursor.moveToFirst();
    int index=cursor.getColumnIndexOrThrow(InstalledAppDb.COLUMN_STATE);
    pkgState=PackageState.valueOf(cursor.getString(index));
    index=cursor.getColumnIndexOrThrow(InstalledAppDb.COLUMN_DOWNLOAD_URI);
    downloadUri=cursor.getString(index);
  }
 catch (  Throwable tr) {
    tr.printStackTrace();
  }
 finally {
    if (null != cursor) {
      cursor.close();
    }
  }
  if (bAppExistsInDb && isDownloadingOrInstalling(pkgState)) {
    Log.i(TAG,"String_Node_Str" + appInfo.mAppCode);
    PackageStateSender.sendPackageStateBroadcast(this,appInfo.mAppCode,pkgState.name());
  }
 else {
    try {
      URI uri=getURI(url);
      Log.i(TAG,"String_Node_Str" + uri.toString());
      ContentValues values=new ContentValues();
      values.put(Downloads.COLUMN_URI,uri.toString());
      values.put(Downloads.COLUMN_NOTIFICATION_PACKAGE,this.getPackageName());
      values.put(Downloads.COLUMN_NOTIFICATION_CLASS,DownloadReceiver.class.getCanonicalName());
      values.put(Downloads.COLUMN_VISIBILITY,Downloads.VISIBILITY_HIDDEN);
      values.put(Downloads.COLUMN_MIME_TYPE,mimetype);
      values.put(Downloads.COLUMN_DESCRIPTION,appInfo.mAppCode);
      values.put(Downloads.COLUMN_NOTIFICATION_EXTRAS,appInfo.mAppCode);
      values.put(Downloads.COLUMN_DESTINATION,Downloads.DESTINATION_CACHE_PARTITION_PURGEABLE);
      values.put(Downloads.COLUMN_TOTAL_BYTES,-1);
      Uri uriInserted=getContentResolver().insert(Downloads.CONTENT_URI,values);
      if (null != uriInserted) {
        Log.i(TAG,"String_Node_Str" + uriInserted.toString());
        ContentValues valuesLocal=new ContentValues(10);
        valuesLocal.put(InstalledAppDb.COLUMN_VERSION,appInfo.mAppVersion);
        valuesLocal.put(InstalledAppDb.COLUMN_APP_NAME,appInfo.mAppName);
        valuesLocal.put(InstalledAppDb.COLUMN_AUTHOR,appInfo.mAppAuthor);
        valuesLocal.put(InstalledAppDb.COLUMN_DESC,appInfo.mAppShortDesc);
        valuesLocal.put(InstalledAppDb.COLUMN_STATE,PackageState.downloading.name());
        valuesLocal.put(InstalledAppDb.COLUMN_IMAGE_URL,appInfo.mAppImageUrl);
        valuesLocal.put(InstalledAppDb.COLUMN_DOWNLOAD_URI,uriInserted.toString());
        if (bAppExistsInDb) {
          try {
            getContentResolver().delete(Uri.parse(downloadUri),null,null);
          }
 catch (          Throwable tr) {
          }
          String where=InstalledAppDb.COLUMN_CODE + "String_Node_Str";
          String[] whereValue={appInfo.mAppCode};
          getContentResolver().update(BehooProvider.INSTALLED_APP_CONTENT_URI,valuesLocal,where,whereValue);
        }
 else {
          valuesLocal.put(InstalledAppDb.COLUMN_CODE,appInfo.mAppCode);
          getContentResolver().insert(BehooProvider.INSTALLED_APP_CONTENT_URI,valuesLocal);
        }
        PackageStateSender.sendPackageStateBroadcast(this,appInfo.mAppCode,InstalledAppDb.PackageState.downloading.name());
      }
 else {
        PackageStateSender.sendPackageStateBroadcast(this,appInfo.mAppCode,InstalledAppDb.PackageState.download_failed.name());
      }
    }
 catch (    Throwable tr) {
      tr.printStackTrace();
    }
  }
}

Fixed version (ground truth):
private void downloadApp(String url,String mimetype,AppInfo appInfo){
  if (null == url || null == mimetype || null == appInfo) {
    throw new NullPointerException();
  }
  if (null == appInfo.mAppCode || null == appInfo.mAppVersion || null == appInfo.mAppName) {
    throw new IllegalArgumentException();
  }
  boolean bAppExistsInDb=false;
  PackageState pkgState=PackageState.unknown;
  String downloadUri=null;
  Cursor cursor=null;
  try {
    String[] columns={InstalledAppDb.COLUMN_CODE,InstalledAppDb.COLUMN_STATE,InstalledAppDb.COLUMN_DOWNLOAD_URI};
    String where=InstalledAppDb.COLUMN_CODE + "String_Node_Str";
    String[] whereValue={appInfo.mAppCode};
    cursor=getContentResolver().query(BehooProvider.INSTALLED_APP_CONTENT_URI,columns,where,whereValue,null);
    bAppExistsInDb=(cursor.getCount() == 1);
    if (cursor.moveToFirst()) {
      int index=cursor.getColumnIndexOrThrow(InstalledAppDb.COLUMN_STATE);
      pkgState=PackageState.valueOf(cursor.getString(index));
      index=cursor.getColumnIndexOrThrow(InstalledAppDb.COLUMN_DOWNLOAD_URI);
      downloadUri=cursor.getString(index);
    }
  }
 catch (  Throwable tr) {
    tr.printStackTrace();
  }
 finally {
    if (null != cursor) {
      cursor.close();
    }
  }
  if (bAppExistsInDb && isDownloadingOrInstalling(pkgState)) {
    Log.i(TAG,"String_Node_Str" + appInfo.mAppCode);
    PackageStateSender.sendPackageStateBroadcast(this,appInfo.mAppCode,pkgState.name());
  }
 else {
    try {
      URI uri=getURI(url);
      Log.i(TAG,"String_Node_Str" + uri.toString());
      ContentValues values=new ContentValues();
      values.put(Downloads.COLUMN_URI,uri.toString());
      values.put(Downloads.COLUMN_NOTIFICATION_PACKAGE,this.getPackageName());
      values.put(Downloads.COLUMN_NOTIFICATION_CLASS,DownloadReceiver.class.getCanonicalName());
      values.put(Downloads.COLUMN_VISIBILITY,Downloads.VISIBILITY_HIDDEN);
      values.put(Downloads.COLUMN_MIME_TYPE,mimetype);
      values.put(Downloads.COLUMN_DESCRIPTION,appInfo.mAppCode);
      values.put(Downloads.COLUMN_NOTIFICATION_EXTRAS,appInfo.mAppCode);
      values.put(Downloads.COLUMN_DESTINATION,Downloads.DESTINATION_CACHE_PARTITION_PURGEABLE);
      values.put(Downloads.COLUMN_TOTAL_BYTES,-1);
      Uri uriInserted=getContentResolver().insert(Downloads.CONTENT_URI,values);
      if (null != uriInserted) {
        Log.i(TAG,"String_Node_Str" + uriInserted.toString());
        ContentValues valuesLocal=new ContentValues(10);
        valuesLocal.put(InstalledAppDb.COLUMN_VERSION,appInfo.mAppVersion);
        valuesLocal.put(InstalledAppDb.COLUMN_APP_NAME,appInfo.mAppName);
        valuesLocal.put(InstalledAppDb.COLUMN_AUTHOR,appInfo.mAppAuthor);
        valuesLocal.put(InstalledAppDb.COLUMN_DESC,appInfo.mAppShortDesc);
        valuesLocal.put(InstalledAppDb.COLUMN_STATE,PackageState.downloading.name());
        valuesLocal.put(InstalledAppDb.COLUMN_IMAGE_URL,appInfo.mAppImageUrl);
        valuesLocal.put(InstalledAppDb.COLUMN_DOWNLOAD_URI,uriInserted.toString());
        if (bAppExistsInDb) {
          try {
            getContentResolver().delete(Uri.parse(downloadUri),null,null);
          }
 catch (          Throwable tr) {
          }
          String where=InstalledAppDb.COLUMN_CODE + "String_Node_Str";
          String[] whereValue={appInfo.mAppCode};
          getContentResolver().update(BehooProvider.INSTALLED_APP_CONTENT_URI,valuesLocal,where,whereValue);
        }
 else {
          valuesLocal.put(InstalledAppDb.COLUMN_CODE,appInfo.mAppCode);
          getContentResolver().insert(BehooProvider.INSTALLED_APP_CONTENT_URI,valuesLocal);
        }
        PackageStateSender.sendPackageStateBroadcast(this,appInfo.mAppCode,InstalledAppDb.PackageState.downloading.name());
      }
 else {
        PackageStateSender.sendPackageStateBroadcast(this,appInfo.mAppCode,InstalledAppDb.PackageState.download_failed.name());
      }
    }
 catch (    Throwable tr) {
      tr.printStackTrace();
    }
  }
}