Program: 152418
Project: 152418
Buggy source:
private boolean updateAccountsInBackground(Account[] systemAccounts){
  if (!haveAccountsChanged(systemAccounts)) {
    return false;
  }
  if ("String_Node_Str".equals(SystemProperties.get(DEBUG_PROPERTY_KEEP_STALE_ACCOUNT_DATA))) {
    Log.w(TAG,"String_Node_Str" + DEBUG_PROPERTY_KEEP_STALE_ACCOUNT_DATA);
    return true;
  }
  Log.i(TAG,"String_Node_Str");
  invalidateFastScrollingIndexCache();
  final ContactsDatabaseHelper dbHelper=mDbHelper.get();
  final SQLiteDatabase db=dbHelper.getWritableDatabase();
  db.beginTransaction();
  try {
    final Set<AccountWithDataSet> knownAccountsWithDataSets=dbHelper.getAllAccountsWithDataSets();
    final List<AccountWithDataSet> accountsWithDataSetsToDelete=Lists.newArrayList();
    for (    AccountWithDataSet knownAccountWithDataSet : knownAccountsWithDataSets) {
      if (knownAccountWithDataSet.isLocalAccount() || knownAccountWithDataSet.inSystemAccounts(systemAccounts)) {
        continue;
      }
      accountsWithDataSetsToDelete.add(knownAccountWithDataSet);
    }
    if (!accountsWithDataSetsToDelete.isEmpty()) {
      for (      AccountWithDataSet accountWithDataSet : accountsWithDataSetsToDelete) {
        Log.d(TAG,"String_Node_Str" + accountWithDataSet);
        final Long accountIdOrNull=dbHelper.getAccountIdOrNull(accountWithDataSet);
        if (accountIdOrNull != null) {
          final String[] accountIdParams=new String[]{Long.toString(accountIdOrNull)};
          db.execSQL("String_Node_Str" + Tables.GROUPS + "String_Node_Str"+ GroupsColumns.ACCOUNT_ID+ "String_Node_Str",accountIdParams);
          db.execSQL("String_Node_Str" + Tables.PRESENCE + "String_Node_Str"+ PresenceColumns.RAW_CONTACT_ID+ "String_Node_Str"+ "String_Node_Str"+ RawContacts._ID+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ RawContactsColumns.ACCOUNT_ID+ "String_Node_Str",accountIdParams);
          db.execSQL("String_Node_Str" + Tables.STREAM_ITEM_PHOTOS + "String_Node_Str"+ StreamItemPhotos.STREAM_ITEM_ID+ "String_Node_Str"+ "String_Node_Str"+ StreamItems._ID+ "String_Node_Str"+ Tables.STREAM_ITEMS+ "String_Node_Str"+ StreamItems.RAW_CONTACT_ID+ "String_Node_Str"+ "String_Node_Str"+ RawContacts._ID+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ RawContactsColumns.ACCOUNT_ID+ "String_Node_Str",accountIdParams);
          db.execSQL("String_Node_Str" + Tables.STREAM_ITEMS + "String_Node_Str"+ StreamItems.RAW_CONTACT_ID+ "String_Node_Str"+ "String_Node_Str"+ RawContacts._ID+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ RawContactsColumns.ACCOUNT_ID+ "String_Node_Str",accountIdParams);
          if (!inProfileMode()) {
            HashSet<Long> rawContactIds=Sets.newHashSet();
            final Cursor cursor=db.rawQuery("String_Node_Str" + RawContactsColumns.CONCRETE_ID + "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ RawContactsColumns.ACCOUNT_ID+ "String_Node_Str",accountIdParams);
            try {
              while (cursor.moveToNext()) {
                final long rawContactId=cursor.getLong(0);
                rawContactIds.add(rawContactId);
                ContactsTableUtil.deleteContactIfSingleton(db,rawContactId);
              }
            }
  finally {
              MoreCloseables.closeQuietly(cursor);
            }
            ContactsTableUtil.updateContactLastUpdate(db,rawContactIds);
          }
          db.execSQL("String_Node_Str" + Tables.RAW_CONTACTS + "String_Node_Str"+ RawContactsColumns.ACCOUNT_ID+ "String_Node_Str",accountIdParams);
          db.execSQL("String_Node_Str" + Tables.ACCOUNTS + "String_Node_Str"+ AccountsColumns._ID+ "String_Node_Str",accountIdParams);
        }
      }
      HashSet<Long> orphanContactIds=Sets.newHashSet();
      Cursor cursor=db.rawQuery("String_Node_Str" + Contacts._ID + "String_Node_Str"+ Tables.CONTACTS+ "String_Node_Str"+ Contacts.NAME_RAW_CONTACT_ID+ "String_Node_Str"+ Contacts.NAME_RAW_CONTACT_ID+ "String_Node_Str"+ "String_Node_Str"+ RawContacts._ID+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ "String_Node_Str"+ Contacts.PHOTO_ID+ "String_Node_Str"+ Contacts.PHOTO_ID+ "String_Node_Str"+ "String_Node_Str"+ Data._ID+ "String_Node_Str"+ Tables.DATA+ "String_Node_Str",null);
      try {
        while (cursor.moveToNext()) {
          orphanContactIds.add(cursor.getLong(0));
        }
      }
  finally {
        cursor.close();
      }
      for (      Long contactId : orphanContactIds) {
        mAggregator.get().updateAggregateData(mTransactionContext.get(),contactId);
      }
      dbHelper.updateAllVisible();
      if (!inProfileMode()) {
        updateSearchIndexInTransaction();
      }
    }
    removeStaleAccountRows(Tables.SETTINGS,Settings.ACCOUNT_NAME,Settings.ACCOUNT_TYPE,systemAccounts);
    removeStaleAccountRows(Tables.DIRECTORIES,Directory.ACCOUNT_NAME,Directory.ACCOUNT_TYPE,systemAccounts);
    dbHelper.getSyncState().onAccountsChanged(db,systemAccounts);
    saveAccounts(systemAccounts);
    db.setTransactionSuccessful();
  }
  finally {
    db.endTransaction();
  }
  mAccountWritability.clear();
  updateContactsAccountCount(systemAccounts);
  updateProviderStatus();
  return true;
}

Fixed version (ground truth):
private boolean updateAccountsInBackground(Account[] systemAccounts){
  if (!haveAccountsChanged(systemAccounts)) {
    return false;
  }
  if ("String_Node_Str".equals(SystemProperties.get(DEBUG_PROPERTY_KEEP_STALE_ACCOUNT_DATA))) {
    Log.w(TAG,"String_Node_Str" + DEBUG_PROPERTY_KEEP_STALE_ACCOUNT_DATA);
    return true;
  }
  Log.i(TAG,"String_Node_Str");
  invalidateFastScrollingIndexCache();
  final ContactsDatabaseHelper dbHelper=mDbHelper.get();
  final SQLiteDatabase db=dbHelper.getWritableDatabase();
  db.beginTransaction();
  try {
    final Set<AccountWithDataSet> knownAccountsWithDataSets=dbHelper.getAllAccountsWithDataSets();
    final List<AccountWithDataSet> accountsWithDataSetsToDelete=Lists.newArrayList();
    for (    AccountWithDataSet knownAccountWithDataSet : knownAccountsWithDataSets) {
      if (knownAccountWithDataSet.isLocalAccount() || knownAccountWithDataSet.inSystemAccounts(systemAccounts)) {
        continue;
      }
      accountsWithDataSetsToDelete.add(knownAccountWithDataSet);
    }
    if (!accountsWithDataSetsToDelete.isEmpty()) {
      for (      AccountWithDataSet accountWithDataSet : accountsWithDataSetsToDelete) {
        Log.d(TAG,"String_Node_Str" + accountWithDataSet);
        final Long accountIdOrNull=dbHelper.getAccountIdOrNull(accountWithDataSet);
        if (accountIdOrNull != null) {
          final String accountId=Long.toString(accountIdOrNull);
          final String[] accountIdParams=new String[]{accountId};
          db.execSQL("String_Node_Str" + Tables.GROUPS + "String_Node_Str"+ GroupsColumns.ACCOUNT_ID+ "String_Node_Str",accountIdParams);
          db.execSQL("String_Node_Str" + Tables.PRESENCE + "String_Node_Str"+ PresenceColumns.RAW_CONTACT_ID+ "String_Node_Str"+ "String_Node_Str"+ RawContacts._ID+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ RawContactsColumns.ACCOUNT_ID+ "String_Node_Str",accountIdParams);
          db.execSQL("String_Node_Str" + Tables.STREAM_ITEM_PHOTOS + "String_Node_Str"+ StreamItemPhotos.STREAM_ITEM_ID+ "String_Node_Str"+ "String_Node_Str"+ StreamItems._ID+ "String_Node_Str"+ Tables.STREAM_ITEMS+ "String_Node_Str"+ StreamItems.RAW_CONTACT_ID+ "String_Node_Str"+ "String_Node_Str"+ RawContacts._ID+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ RawContactsColumns.ACCOUNT_ID+ "String_Node_Str",accountIdParams);
          db.execSQL("String_Node_Str" + Tables.STREAM_ITEMS + "String_Node_Str"+ StreamItems.RAW_CONTACT_ID+ "String_Node_Str"+ "String_Node_Str"+ RawContacts._ID+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ RawContactsColumns.ACCOUNT_ID+ "String_Node_Str",accountIdParams);
          if (!inProfileMode()) {
            Cursor cursor=db.rawQuery("String_Node_Str" + RawContactsColumns.CONCRETE_CONTACT_ID + "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ RawContactsColumns.ACCOUNT_ID+ "String_Node_Str"+ "String_Node_Str"+ RawContactsColumns.CONCRETE_CONTACT_ID+ "String_Node_Str"+ "String_Node_Str"+ RawContactsColumns.CONCRETE_CONTACT_ID+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ RawContactsColumns.ACCOUNT_ID+ "String_Node_Str"+ "String_Node_Str",accountIdParams);
            try {
              while (cursor.moveToNext()) {
                final long contactId=cursor.getLong(0);
                ContactsTableUtil.deleteContact(db,contactId);
              }
            }
  finally {
              MoreCloseables.closeQuietly(cursor);
            }
            cursor=db.rawQuery("String_Node_Str" + RawContactsColumns.CONCRETE_CONTACT_ID + "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ RawContactsColumns.ACCOUNT_ID+ "String_Node_Str"+ "String_Node_Str"+ RawContactsColumns.CONCRETE_CONTACT_ID+ "String_Node_Str"+ "String_Node_Str"+ RawContactsColumns.CONCRETE_CONTACT_ID+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ RawContactsColumns.ACCOUNT_ID+ "String_Node_Str"+ "String_Node_Str",accountIdParams);
            try {
              while (cursor.moveToNext()) {
                final long contactId=cursor.getLong(0);
                ContactsTableUtil.updateContactLastUpdateByContactId(db,contactId);
              }
            }
  finally {
              MoreCloseables.closeQuietly(cursor);
            }
          }
          db.execSQL("String_Node_Str" + Tables.RAW_CONTACTS + "String_Node_Str"+ RawContactsColumns.ACCOUNT_ID+ "String_Node_Str",accountIdParams);
          db.execSQL("String_Node_Str" + Tables.ACCOUNTS + "String_Node_Str"+ AccountsColumns._ID+ "String_Node_Str",accountIdParams);
        }
      }
      HashSet<Long> orphanContactIds=Sets.newHashSet();
      Cursor cursor=db.rawQuery("String_Node_Str" + Contacts._ID + "String_Node_Str"+ Tables.CONTACTS+ "String_Node_Str"+ Contacts.NAME_RAW_CONTACT_ID+ "String_Node_Str"+ Contacts.NAME_RAW_CONTACT_ID+ "String_Node_Str"+ "String_Node_Str"+ RawContacts._ID+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ "String_Node_Str"+ Contacts.PHOTO_ID+ "String_Node_Str"+ Contacts.PHOTO_ID+ "String_Node_Str"+ "String_Node_Str"+ Data._ID+ "String_Node_Str"+ Tables.DATA+ "String_Node_Str",null);
      try {
        while (cursor.moveToNext()) {
          orphanContactIds.add(cursor.getLong(0));
        }
      }
  finally {
        cursor.close();
      }
      for (      Long contactId : orphanContactIds) {
        mAggregator.get().updateAggregateData(mTransactionContext.get(),contactId);
      }
      dbHelper.updateAllVisible();
      if (!inProfileMode()) {
        updateSearchIndexInTransaction();
      }
    }
    removeStaleAccountRows(Tables.SETTINGS,Settings.ACCOUNT_NAME,Settings.ACCOUNT_TYPE,systemAccounts);
    removeStaleAccountRows(Tables.DIRECTORIES,Directory.ACCOUNT_NAME,Directory.ACCOUNT_TYPE,systemAccounts);
    dbHelper.getSyncState().onAccountsChanged(db,systemAccounts);
    saveAccounts(systemAccounts);
    db.setTransactionSuccessful();
  }
  finally {
    db.endTransaction();
  }
  mAccountWritability.clear();
  updateContactsAccountCount(systemAccounts);
  updateProviderStatus();
  return true;
}