nus-yam/ex-repair huggingface dataset:
Program: 152364
Project: 152364
Buggy source:
public static synchronized void setLocales(LocaleSet locales){
  if (sSingleton == null || !sSingleton.isLocale(locales)) {
    sSingleton=new ContactLocaleUtils(locales);
  }
}

Fixed version (ground truth):
public static synchronized void setLocales(LocaleSet locales){
  if (sSingleton == null || !sSingleton.isLocale(locales)) {
    if (DEBUG) {
      Log.d(TAG,"String_Node_Str" + locales);
    }
    sSingleton=new ContactLocaleUtils(locales);
  }
}
Program: 152365
Project: 152365
Buggy source:
/** 
 * Verifies that the contacts database is properly configured for the current locale. If not, changes the database locale to the current locale using an asynchronous task. This needs to be done asynchronously because the process involves rebuilding large data structures (name lookup, sort keys), which can take minutes on a large set of contacts.
 */
protected void updateLocaleInBackground(){
  if (mProviderStatus == STATUS_CHANGING_LOCALE) {
    return;
  }
  final LocaleSet currentLocales=mCurrentLocales;
  final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(getContext());
  if (!needsToUpdateLocaleData(prefs,currentLocales,mContactsHelper,mProfileHelper)) {
    return;
  }
  int providerStatus=mProviderStatus;
  setProviderStatus(STATUS_CHANGING_LOCALE);
  mContactsHelper.setLocale(currentLocales);
  mProfileHelper.setLocale(currentLocales);
  mSearchIndexManager.updateIndex(true);
  prefs.edit().putString(PREF_LOCALE,currentLocales.toString()).commit();
  setProviderStatus(providerStatus);
}

Fixed version (ground truth):
/** 
 * Verifies that the contacts database is properly configured for the current locale. If not, changes the database locale to the current locale using an asynchronous task. This needs to be done asynchronously because the process involves rebuilding large data structures (name lookup, sort keys), which can take minutes on a large set of contacts.
 */
protected void updateLocaleInBackground(){
  if (mProviderStatus == STATUS_CHANGING_LOCALE) {
    return;
  }
  final LocaleSet currentLocales=mCurrentLocales;
  final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(getContext());
  if (!needsToUpdateLocaleData(prefs,currentLocales,mContactsHelper,mProfileHelper)) {
    return;
  }
  int providerStatus=mProviderStatus;
  setProviderStatus(STATUS_CHANGING_LOCALE);
  mContactsHelper.setLocale(currentLocales);
  mProfileHelper.setLocale(currentLocales);
  mSearchIndexManager.updateIndex(true);
  prefs.edit().putString(PREF_LOCALE,currentLocales.toString()).commit();
  setProviderStatus(providerStatus);
  if (!mCurrentLocales.isCurrent()) {
    scheduleBackgroundTask(BACKGROUND_TASK_CHANGE_LOCALE);
  }
}
Program: 152366
Project: 152366
Buggy source:
public ContactLocaleUtilsBase(LocaleSet systemLocales){
  mUsePinyinTransliterator=systemLocales.shouldPreferSimplifiedChinese();
  if (DEBUG) {
    Log.d(TAG,"String_Node_Str");
  }
  final List<Locale> locales=getLocalesForBuckets(systemLocales);
  AlphabeticIndex ai=new AlphabeticIndex(locales.get(0)).setMaxLabelCount(300);
  for (int i=1; i < locales.size(); i++) {
    ai.addLabels(locales.get(i));
  }
  mAlphabeticIndex=ai.buildImmutableIndex();
  mAlphabeticIndexBucketCount=mAlphabeticIndex.getBucketCount();
  mNumberBucketIndex=mAlphabeticIndexBucketCount - 1;
  if (DEBUG) {
    final StringBuilder labels=new StringBuilder();
    String sep="String_Node_Str";
    for (int i=0; i < mAlphabeticIndexBucketCount; i++) {
      labels.append(sep);
      labels.append(mAlphabeticIndex.getBucket(i).getLabel());
      sep="String_Node_Str";
    }
    Log.d(TAG,"String_Node_Str" + labels + "String_Node_Str");
  }
}

Fixed version (ground truth):
public ContactLocaleUtilsBase(LocaleSet systemLocales){
  mUsePinyinTransliterator=systemLocales.shouldPreferSimplifiedChinese();
  if (DEBUG) {
    Log.d(TAG,"String_Node_Str");
  }
  final List<Locale> locales=getLocalesForBuckets(systemLocales);
  AlphabeticIndex ai=new AlphabeticIndex(locales.get(0)).setMaxLabelCount(300);
  for (int i=1; i < locales.size(); i++) {
    ai.addLabels(locales.get(i));
  }
  mAlphabeticIndex=ai.buildImmutableIndex();
  mAlphabeticIndexBucketCount=mAlphabeticIndex.getBucketCount();
  mNumberBucketIndex=mAlphabeticIndexBucketCount - 1;
  if (DEBUG) {
    dumpIndex(mAlphabeticIndex);
  }
}
Program: 152367
Project: 152367
Buggy source:
static List<Locale> getLocalesForBuckets(LocaleSet systemLocales){
  final LocaleList localeList=systemLocales.getAllLocales();
  final List<Locale> locales=new ArrayList<>(localeList.size() + sDefaultLabelLocales.length);
  for (int i=0; i < localeList.size(); i++) {
    locales.add(localeList.get(i));
  }
  for (int i=0; i < sDefaultLabelLocales.length; i++) {
    locales.add(sDefaultLabelLocales[i]);
  }
  final List<Locale> ret=new ArrayList<>(locales.size());
  boolean allowChinese=true;
  for (int i=0; i < locales.size(); i++) {
    final Locale locale=locales.get(i);
    if (ret.contains(locale)) {
      continue;
    }
    if (LocaleSet.isLanguageChinese(locale)) {
      if (!allowChinese) {
        continue;
      }
      allowChinese=false;
    }
    if (LocaleSet.isLanguageJapanese(locale)) {
      allowChinese=false;
    }
    if (DEBUG) {
      Log.d(TAG,"String_Node_Str" + locale);
    }
    ret.add(locale);
  }
  return ret;
}

Fixed version (ground truth):
static List<Locale> getLocalesForBuckets(LocaleSet systemLocales){
  final LocaleList localeList=systemLocales.getAllLocales();
  final List<Locale> locales=new ArrayList<>(localeList.size() + sDefaultLabelLocales.length);
  for (int i=0; i < localeList.size(); i++) {
    locales.add(localeList.get(i));
  }
  for (int i=0; i < sDefaultLabelLocales.length; i++) {
    locales.add(sDefaultLabelLocales[i]);
  }
  final List<Locale> ret=new ArrayList<>(locales.size());
  boolean allowChinese=true;
  for (int i=0; i < locales.size(); i++) {
    final Locale locale=locales.get(i);
    if (ret.contains(locale)) {
      continue;
    }
    if (LocaleSet.isLanguageChinese(locale)) {
      if (!allowChinese) {
        continue;
      }
      allowChinese=false;
    }
    if (LocaleSet.isLanguageJapanese(locale)) {
      allowChinese=false;
    }
    if (DEBUG) {
      Log.d(TAG,"String_Node_Str" + locale.toLanguageTag());
    }
    ret.add(locale);
  }
  return ret;
}
Program: 152368
Project: 152368
Buggy source:
/** 
 * @return true if Japanese is found in the list before simplified Chinese.
 */
public boolean shouldPreferJapanese(){
  if (isLanguageJapanese(getPrimaryLocale())) {
    return true;
  }
  for (int i=0; i < mLocaleList.size(); i++) {
    final Locale l=mLocaleList.get(i);
    if (isLanguageJapanese(l)) {
      return true;
    }
    if (isLocaleSimplifiedChinese(l)) {
      return false;
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * @return true if Japanese is found in the list before simplified Chinese.
 */
public boolean shouldPreferJapanese(){
  if (isLanguageJapanese(getPrimaryLocale())) {
    return true;
  }
  for (int i=0; i < mLocaleList.size(); i++) {
    final Locale l=mLocaleList.get(i);
    if (isLanguageJapanese(l)) {
      return true;
    }
    if (isLanguageChinese(l)) {
      return false;
    }
  }
  return false;
}
Program: 152369
Project: 152369
Buggy source:
public void testShouldPreferJapanese(){
  assertFalse(LocaleSet.newForTest(Locale.ENGLISH).shouldPreferJapanese());
  assertTrue(LocaleSet.newForTest(Locale.JAPAN).shouldPreferJapanese());
  assertTrue(LocaleSet.newForTest(Locale.ENGLISH,Locale.KOREAN,Locale.JAPAN).shouldPreferJapanese());
  assertTrue(LocaleSet.newForTest(Locale.JAPAN,Locale.TRADITIONAL_CHINESE).shouldPreferJapanese());
  assertTrue(LocaleSet.newForTest(Locale.JAPAN,Locale.SIMPLIFIED_CHINESE).shouldPreferJapanese());
  assertTrue(LocaleSet.newForTest(Locale.TRADITIONAL_CHINESE,Locale.JAPAN).shouldPreferJapanese());
  assertFalse(LocaleSet.newForTest(Locale.SIMPLIFIED_CHINESE,Locale.JAPAN).shouldPreferJapanese());
  assertFalse(LocaleSet.newForTest(Locale.ENGLISH,Locale.SIMPLIFIED_CHINESE,Locale.JAPAN).shouldPreferJapanese());
}

Fixed version (ground truth):
public void testShouldPreferJapanese(){
  assertFalse(LocaleSet.newForTest(Locale.ENGLISH).shouldPreferJapanese());
  assertTrue(LocaleSet.newForTest(Locale.JAPAN).shouldPreferJapanese());
  assertTrue(LocaleSet.newForTest(Locale.ENGLISH,Locale.KOREAN,Locale.JAPAN).shouldPreferJapanese());
  assertTrue(LocaleSet.newForTest(Locale.JAPAN,Locale.TRADITIONAL_CHINESE).shouldPreferJapanese());
  assertTrue(LocaleSet.newForTest(Locale.JAPAN,Locale.SIMPLIFIED_CHINESE).shouldPreferJapanese());
  assertFalse(LocaleSet.newForTest(Locale.TRADITIONAL_CHINESE,Locale.JAPAN).shouldPreferJapanese());
  assertFalse(LocaleSet.newForTest(Locale.SIMPLIFIED_CHINESE,Locale.JAPAN).shouldPreferJapanese());
  assertFalse(LocaleSet.newForTest(Locale.ENGLISH,Locale.SIMPLIFIED_CHINESE,Locale.JAPAN).shouldPreferJapanese());
}
Program: 152372
Project: 152372
Buggy source:
public void clearExceptSearchIndexUpdates(){
  mInsertedRawContactsAccounts=null;
  mUpdatedRawContacts=null;
  mUpdatedSyncStates=null;
  mDirtyRawContacts=null;
  mMetadataDirtyRawContacts=null;
  mChangedRawContacts=null;
}

Fixed version (ground truth):
public void clearExceptSearchIndexUpdates(){
  mInsertedRawContactsAccounts=null;
  mUpdatedRawContacts=null;
  mUpdatedSyncStates=null;
  mDirtyRawContacts=null;
  mMetadataDirtyRawContacts=null;
  mChangedRawContacts=null;
  mBackupIdChangedRawContacts=null;
}
Program: 152373
Project: 152373
Buggy source:
private void upgradeToVersion1101(SQLiteDatabase db){
  final SQLiteStatement update=db.compileStatement("String_Node_Str" + Tables.DATA + "String_Node_Str"+ Data.HASH_ID+ "String_Node_Str"+ "String_Node_Str"+ Data._ID+ "String_Node_Str");
  final String selection=Data.HASH_ID + "String_Node_Str";
  final Cursor c=db.query(Tables.DATA,new String[]{Data._ID,Data.DATA1,Data.DATA2,Data.DATA15},selection,null,null,null,null);
  try {
    while (c.moveToNext()) {
      final long dataId=c.getLong(0);
      final String data1=c.getString(1);
      final String data2=c.getString(2);
      final byte[] data15=c.getBlob(3);
      final String hashId=generateHashId(data1,data2,data15);
      if (!TextUtils.isEmpty(hashId)) {
        update.bindString(1,hashId);
        update.bindLong(2,dataId);
        update.execute();
      }
    }
  }
  finally {
    c.close();
  }
}

Fixed version (ground truth):
public void upgradeToVersion1101(SQLiteDatabase db){
  final SQLiteStatement update=db.compileStatement("String_Node_Str" + Tables.DATA + "String_Node_Str"+ Data.HASH_ID+ "String_Node_Str"+ "String_Node_Str"+ Data._ID+ "String_Node_Str");
  final Cursor c=db.query(Tables.DATA,new String[]{Data._ID,Data.DATA1,Data.DATA2,Data.DATA15},null,null,null,null,Data._ID);
  try {
    while (c.moveToNext()) {
      final long dataId=c.getLong(0);
      final String data1=c.getString(1);
      final String data2=c.getString(2);
      final byte[] data15=c.getBlob(3);
      final String hashId=generateHashId(data1,data2,data15);
      if (!TextUtils.isEmpty(hashId)) {
        update.bindString(1,hashId);
        update.bindLong(2,dataId);
        update.execute();
      }
    }
  }
  finally {
    c.close();
  }
}
Program: 152374
Project: 152374
Buggy source:
@Override public int update(Uri uri,ContentValues values,String selection,String[] selectionArgs){
  final SQLiteDatabase db=mDbHelper.getWritableDatabase();
  db.beginTransaction();
  try {
    final int matchedUriId=sURIMatcher.match(uri);
switch (matchedUriId) {
case SYNC_STATE:
      final long accountId=replaceAccountInfoByAccountId(uri,values);
    values.remove(MetadataSyncColumns.ACCOUNT_ID);
  final String selectionByAccountId=MetadataSyncStateColumns.ACCOUNT_ID + "String_Node_Str";
final String[] args=new String[1];
args[0]=String.valueOf(accountId);
db.update(Tables.METADATA_SYNC_STATE,values,selectionByAccountId,args);
db.setTransactionSuccessful();
return 1;
default :
throw new IllegalArgumentException(mDbHelper.exceptionMessage("String_Node_Str",uri));
}
}
  finally {
db.endTransaction();
}
}

Fixed version (ground truth):
@Override public int update(Uri uri,ContentValues values,String selection,String[] selectionArgs){
  final SQLiteDatabase db=mDbHelper.getWritableDatabase();
  db.beginTransaction();
  try {
    final int matchedUriId=sURIMatcher.match(uri);
switch (matchedUriId) {
case SYNC_STATE:
      final Long accountId=replaceAccountInfoByAccountId(uri,values);
    if (accountId == null) {
      throw new IllegalArgumentException(mDbHelper.exceptionMessage("String_Node_Str",uri));
    }
  values.put(MetadataSyncColumns.ACCOUNT_ID,accountId);
db.replace(Tables.METADATA_SYNC_STATE,null,values);
db.setTransactionSuccessful();
return 1;
default :
throw new IllegalArgumentException(mDbHelper.exceptionMessage("String_Node_Str",uri));
}
}
  finally {
db.endTransaction();
}
}
Program: 152376
Project: 152376
Buggy source:
private void upgradeToVersion1101(SQLiteDatabase db){
  final SQLiteStatement update=db.compileStatement("String_Node_Str" + Tables.DATA + "String_Node_Str"+ Data.HASH_ID+ "String_Node_Str"+ "String_Node_Str"+ Data._ID+ "String_Node_Str");
  final String selection=Data.HASH_ID + "String_Node_Str";
  final Cursor c=db.query(Tables.DATA,new String[]{Data._ID,Data.DATA1,Data.DATA2,Data.DATA15},selection,null,null,null,null);
  try {
    while (c.moveToNext()) {
      final long dataId=c.getLong(0);
      final String data1=c.getString(1);
      final String data2=c.getString(2);
      final byte[] data15=c.getBlob(3);
      final String hashId=generateHashId(data1,data2,data15);
      if (!TextUtils.isEmpty(hashId)) {
        update.bindString(1,hashId);
        update.bindLong(2,dataId);
        update.execute();
      }
    }
  }
  finally {
    c.close();
  }
}

Fixed version (ground truth):
public void upgradeToVersion1101(SQLiteDatabase db){
  final SQLiteStatement update=db.compileStatement("String_Node_Str" + Tables.DATA + "String_Node_Str"+ Data.HASH_ID+ "String_Node_Str"+ "String_Node_Str"+ Data._ID+ "String_Node_Str");
  final Cursor c=db.query(Tables.DATA,new String[]{Data._ID,Data.DATA1,Data.DATA2,Data.DATA15},null,null,null,null,Data._ID);
  try {
    while (c.moveToNext()) {
      final long dataId=c.getLong(0);
      final String data1=c.getString(1);
      final String data2=c.getString(2);
      final byte[] data15=c.getBlob(3);
      final String hashId=generateHashId(data1,data2,data15);
      if (!TextUtils.isEmpty(hashId)) {
        update.bindString(1,hashId);
        update.bindLong(2,dataId);
        update.execute();
      }
    }
  }
  finally {
    c.close();
  }
}
Program: 152377
Project: 152377
Buggy source:
/** 
 * Finds matching contacts and returns a cursor on those.
 */
public final Cursor queryAggregationSuggestions(SQLiteQueryBuilder qb,String[] projection,long contactId,int maxSuggestions,String filter,ArrayList<AggregationSuggestionParameter> parameters){
  final SQLiteDatabase db=mDbHelper.getReadableDatabase();
  db.beginTransaction();
  try {
    List<MatchScore> bestMatches=findMatchingContacts(db,contactId,parameters);
    return queryMatchingContacts(qb,db,projection,bestMatches,maxSuggestions,filter);
  }
  finally {
    db.endTransaction();
  }
}

Fixed version (ground truth):
/** 
 * Finds matching contacts and returns a cursor on those.
 */
public final Cursor queryAggregationSuggestions(SQLiteQueryBuilder qb,String[] projection,long contactId,int maxSuggestions,String filter,ArrayList<AggregationSuggestionParameter> parameters){
  final SQLiteDatabase db=mDbHelper.getReadableDatabase();
  db.beginTransaction();
  try {
    List<MatchScore> bestMatches=findMatchingContacts(db,contactId,parameters);
    List<MatchScore> bestMatchesWithoutDuplicateContactIds=new ArrayList<>();
    Set<Long> contactIds=new HashSet<>();
    for (    MatchScore bestMatch : bestMatches) {
      long cid=bestMatch.getContactId();
      if (!contactIds.contains(cid)) {
        bestMatchesWithoutDuplicateContactIds.add(bestMatch);
        contactIds.add(cid);
      }
    }
    return queryMatchingContacts(qb,db,projection,bestMatchesWithoutDuplicateContactIds,maxSuggestions,filter);
  }
  finally {
    db.endTransaction();
  }
}
Program: 152378
Project: 152378
Buggy source:
public void testAggregationSuggestionsBasedOnName(){
  long rawContactId1=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId1,"String_Node_Str",null);
  long rawContactId2=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId2,"String_Node_Str",null);
  setAggregationException(AggregationExceptions.TYPE_KEEP_SEPARATE,rawContactId1,rawContactId2);
  long rawContactId3=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId3,"String_Node_Str",null);
  long rawContactId4=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId4,"String_Node_Str",null);
  long contactId1=queryContactId(rawContactId1);
  long contactId2=queryContactId(rawContactId2);
  long contactId3=queryContactId(rawContactId3);
  assertSuggestions(contactId1,contactId2,contactId3);
}

Fixed version (ground truth):
public void testAggregationSuggestionsBasedOnName(){
  long rawContactId1=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId1,"String_Node_Str",null);
  insertPhoneNumber(rawContactId1,"String_Node_Str");
  long rawContactId2=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId2,"String_Node_Str",null);
  insertPhoneNumber(rawContactId2,"String_Node_Str");
  long rawContactId3=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId3,"String_Node_Str",null);
  long rawContactId4=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId4,"String_Node_Str",null);
  long rawContactId5=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId5,"String_Node_Str",null);
  long contactId1=queryContactId(rawContactId1);
  long contactId2=queryContactId(rawContactId2);
  long contactId3=queryContactId(rawContactId3);
  assertEquals(contactId1,contactId2);
  assertSuggestions(queryContactId(rawContactId5),contactId1,contactId3);
}
Program: 152379
Project: 152379
Buggy source:
/** 
 * Finds matching contacts and returns a cursor on those.
 */
public final Cursor queryAggregationSuggestions(SQLiteQueryBuilder qb,String[] projection,long contactId,int maxSuggestions,String filter,ArrayList<AggregationSuggestionParameter> parameters){
  final SQLiteDatabase db=mDbHelper.getReadableDatabase();
  db.beginTransaction();
  try {
    List<MatchScore> bestMatches=findMatchingContacts(db,contactId,parameters);
    return queryMatchingContacts(qb,db,projection,bestMatches,maxSuggestions,filter);
  }
  finally {
    db.endTransaction();
  }
}

Fixed version (ground truth):
/** 
 * Finds matching contacts and returns a cursor on those.
 */
public final Cursor queryAggregationSuggestions(SQLiteQueryBuilder qb,String[] projection,long contactId,int maxSuggestions,String filter,ArrayList<AggregationSuggestionParameter> parameters){
  final SQLiteDatabase db=mDbHelper.getReadableDatabase();
  db.beginTransaction();
  try {
    List<MatchScore> bestMatches=findMatchingContacts(db,contactId,parameters);
    List<MatchScore> bestMatchesWithoutDuplicateContactIds=new ArrayList<>();
    Set<Long> contactIds=new HashSet<>();
    for (    MatchScore bestMatch : bestMatches) {
      long cid=bestMatch.getContactId();
      if (!contactIds.contains(cid)) {
        bestMatchesWithoutDuplicateContactIds.add(bestMatch);
        contactIds.add(cid);
      }
    }
    return queryMatchingContacts(qb,db,projection,bestMatchesWithoutDuplicateContactIds,maxSuggestions,filter);
  }
  finally {
    db.endTransaction();
  }
}
Program: 152380
Project: 152380
Buggy source:
public void testAggregationSuggestionsBasedOnName(){
  long rawContactId1=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId1,"String_Node_Str",null);
  long rawContactId2=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId2,"String_Node_Str",null);
  setAggregationException(AggregationExceptions.TYPE_KEEP_SEPARATE,rawContactId1,rawContactId2);
  long rawContactId3=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId3,"String_Node_Str",null);
  long rawContactId4=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId4,"String_Node_Str",null);
  long contactId1=queryContactId(rawContactId1);
  long contactId2=queryContactId(rawContactId2);
  long contactId3=queryContactId(rawContactId3);
  assertSuggestions(contactId1,contactId2,contactId3);
}

Fixed version (ground truth):
public void testAggregationSuggestionsBasedOnName(){
  long rawContactId1=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId1,"String_Node_Str",null);
  insertPhoneNumber(rawContactId1,"String_Node_Str");
  long rawContactId2=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId2,"String_Node_Str",null);
  insertPhoneNumber(rawContactId2,"String_Node_Str");
  long rawContactId3=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId3,"String_Node_Str",null);
  long rawContactId4=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId4,"String_Node_Str",null);
  long rawContactId5=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId5,"String_Node_Str",null);
  long contactId1=queryContactId(rawContactId1);
  long contactId2=queryContactId(rawContactId2);
  long contactId3=queryContactId(rawContactId3);
  assertEquals(contactId1,contactId2);
  assertSuggestions(queryContactId(rawContactId5),contactId1,contactId3);
}
Program: 152381
Project: 152381
Buggy source:
/** 
 * Finds matching contacts and returns a cursor on those.
 */
public final Cursor queryAggregationSuggestions(SQLiteQueryBuilder qb,String[] projection,long contactId,int maxSuggestions,String filter,ArrayList<AggregationSuggestionParameter> parameters){
  final SQLiteDatabase db=mDbHelper.getReadableDatabase();
  db.beginTransaction();
  try {
    List<MatchScore> bestMatches=findMatchingContacts(db,contactId,parameters);
    return queryMatchingContacts(qb,db,projection,bestMatches,maxSuggestions,filter);
  }
  finally {
    db.endTransaction();
  }
}

Fixed version (ground truth):
/** 
 * Finds matching contacts and returns a cursor on those.
 */
public final Cursor queryAggregationSuggestions(SQLiteQueryBuilder qb,String[] projection,long contactId,int maxSuggestions,String filter,ArrayList<AggregationSuggestionParameter> parameters){
  final SQLiteDatabase db=mDbHelper.getReadableDatabase();
  db.beginTransaction();
  try {
    List<MatchScore> bestMatches=findMatchingContacts(db,contactId,parameters);
    List<MatchScore> bestMatchesWithoutDuplicateContactIds=new ArrayList<>();
    Set<Long> contactIds=new HashSet<>();
    for (    MatchScore bestMatch : bestMatches) {
      long cid=bestMatch.getContactId();
      if (!contactIds.contains(cid)) {
        bestMatchesWithoutDuplicateContactIds.add(bestMatch);
        contactIds.add(cid);
      }
    }
    return queryMatchingContacts(qb,db,projection,bestMatchesWithoutDuplicateContactIds,maxSuggestions,filter);
  }
  finally {
    db.endTransaction();
  }
}
Program: 152382
Project: 152382
Buggy source:
public void testAggregationSuggestionsBasedOnName(){
  long rawContactId1=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId1,"String_Node_Str",null);
  long rawContactId2=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId2,"String_Node_Str",null);
  setAggregationException(AggregationExceptions.TYPE_KEEP_SEPARATE,rawContactId1,rawContactId2);
  long rawContactId3=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId3,"String_Node_Str",null);
  long rawContactId4=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId4,"String_Node_Str",null);
  long contactId1=queryContactId(rawContactId1);
  long contactId2=queryContactId(rawContactId2);
  long contactId3=queryContactId(rawContactId3);
  assertSuggestions(contactId1,contactId2,contactId3);
}

Fixed version (ground truth):
public void testAggregationSuggestionsBasedOnName(){
  long rawContactId1=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId1,"String_Node_Str",null);
  insertPhoneNumber(rawContactId1,"String_Node_Str");
  long rawContactId2=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId2,"String_Node_Str",null);
  insertPhoneNumber(rawContactId2,"String_Node_Str");
  long rawContactId3=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId3,"String_Node_Str",null);
  long rawContactId4=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId4,"String_Node_Str",null);
  long rawContactId5=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId5,"String_Node_Str",null);
  long contactId1=queryContactId(rawContactId1);
  long contactId2=queryContactId(rawContactId2);
  long contactId3=queryContactId(rawContactId3);
  assertEquals(contactId1,contactId2);
  assertSuggestions(queryContactId(rawContactId5),contactId1,contactId3);
}
Program: 152383
Project: 152383
Buggy source:
/** 
 * Finds matching contacts and returns a cursor on those.
 */
public final Cursor queryAggregationSuggestions(SQLiteQueryBuilder qb,String[] projection,long contactId,int maxSuggestions,String filter,ArrayList<AggregationSuggestionParameter> parameters){
  final SQLiteDatabase db=mDbHelper.getReadableDatabase();
  db.beginTransaction();
  try {
    List<MatchScore> bestMatches=findMatchingContacts(db,contactId,parameters);
    return queryMatchingContacts(qb,db,projection,bestMatches,maxSuggestions,filter);
  }
  finally {
    db.endTransaction();
  }
}

Fixed version (ground truth):
/** 
 * Finds matching contacts and returns a cursor on those.
 */
public final Cursor queryAggregationSuggestions(SQLiteQueryBuilder qb,String[] projection,long contactId,int maxSuggestions,String filter,ArrayList<AggregationSuggestionParameter> parameters){
  final SQLiteDatabase db=mDbHelper.getReadableDatabase();
  db.beginTransaction();
  try {
    List<MatchScore> bestMatches=findMatchingContacts(db,contactId,parameters);
    List<MatchScore> bestMatchesWithoutDuplicateContactIds=new ArrayList<>();
    Set<Long> contactIds=new HashSet<>();
    for (    MatchScore bestMatch : bestMatches) {
      long cid=bestMatch.getContactId();
      if (!contactIds.contains(cid)) {
        bestMatchesWithoutDuplicateContactIds.add(bestMatch);
        contactIds.add(cid);
      }
    }
    return queryMatchingContacts(qb,db,projection,bestMatchesWithoutDuplicateContactIds,maxSuggestions,filter);
  }
  finally {
    db.endTransaction();
  }
}
Program: 152384
Project: 152384
Buggy source:
public void testAggregationSuggestionsBasedOnName(){
  long rawContactId1=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId1,"String_Node_Str",null);
  long rawContactId2=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId2,"String_Node_Str",null);
  setAggregationException(AggregationExceptions.TYPE_KEEP_SEPARATE,rawContactId1,rawContactId2);
  long rawContactId3=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId3,"String_Node_Str",null);
  long rawContactId4=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId4,"String_Node_Str",null);
  long contactId1=queryContactId(rawContactId1);
  long contactId2=queryContactId(rawContactId2);
  long contactId3=queryContactId(rawContactId3);
  assertSuggestions(contactId1,contactId2,contactId3);
}

Fixed version (ground truth):
public void testAggregationSuggestionsBasedOnName(){
  long rawContactId1=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId1,"String_Node_Str",null);
  insertPhoneNumber(rawContactId1,"String_Node_Str");
  long rawContactId2=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId2,"String_Node_Str",null);
  insertPhoneNumber(rawContactId2,"String_Node_Str");
  long rawContactId3=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId3,"String_Node_Str",null);
  long rawContactId4=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId4,"String_Node_Str",null);
  long rawContactId5=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId5,"String_Node_Str",null);
  long contactId1=queryContactId(rawContactId1);
  long contactId2=queryContactId(rawContactId2);
  long contactId3=queryContactId(rawContactId3);
  assertEquals(contactId1,contactId2);
  assertSuggestions(queryContactId(rawContactId5),contactId1,contactId3);
}
Program: 152385
Project: 152385
Buggy source:
/** 
 * Finds matching contacts and returns a cursor on those.
 */
public final Cursor queryAggregationSuggestions(SQLiteQueryBuilder qb,String[] projection,long contactId,int maxSuggestions,String filter,ArrayList<AggregationSuggestionParameter> parameters){
  final SQLiteDatabase db=mDbHelper.getReadableDatabase();
  db.beginTransaction();
  try {
    List<MatchScore> bestMatches=findMatchingContacts(db,contactId,parameters);
    return queryMatchingContacts(qb,db,projection,bestMatches,maxSuggestions,filter);
  }
  finally {
    db.endTransaction();
  }
}

Fixed version (ground truth):
/** 
 * Finds matching contacts and returns a cursor on those.
 */
public final Cursor queryAggregationSuggestions(SQLiteQueryBuilder qb,String[] projection,long contactId,int maxSuggestions,String filter,ArrayList<AggregationSuggestionParameter> parameters){
  final SQLiteDatabase db=mDbHelper.getReadableDatabase();
  db.beginTransaction();
  try {
    List<MatchScore> bestMatches=findMatchingContacts(db,contactId,parameters);
    List<MatchScore> bestMatchesWithoutDuplicateContactIds=new ArrayList<>();
    Set<Long> contactIds=new HashSet<>();
    for (    MatchScore bestMatch : bestMatches) {
      long cid=bestMatch.getContactId();
      if (!contactIds.contains(cid)) {
        bestMatchesWithoutDuplicateContactIds.add(bestMatch);
        contactIds.add(cid);
      }
    }
    return queryMatchingContacts(qb,db,projection,bestMatchesWithoutDuplicateContactIds,maxSuggestions,filter);
  }
  finally {
    db.endTransaction();
  }
}
Program: 152386
Project: 152386
Buggy source:
public void testAggregationSuggestionsBasedOnName(){
  long rawContactId1=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId1,"String_Node_Str",null);
  long rawContactId2=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId2,"String_Node_Str",null);
  setAggregationException(AggregationExceptions.TYPE_KEEP_SEPARATE,rawContactId1,rawContactId2);
  long rawContactId3=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId3,"String_Node_Str",null);
  long rawContactId4=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId4,"String_Node_Str",null);
  long contactId1=queryContactId(rawContactId1);
  long contactId2=queryContactId(rawContactId2);
  long contactId3=queryContactId(rawContactId3);
  assertSuggestions(contactId1,contactId2,contactId3);
}

Fixed version (ground truth):
public void testAggregationSuggestionsBasedOnName(){
  long rawContactId1=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId1,"String_Node_Str",null);
  insertPhoneNumber(rawContactId1,"String_Node_Str");
  long rawContactId2=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId2,"String_Node_Str",null);
  insertPhoneNumber(rawContactId2,"String_Node_Str");
  long rawContactId3=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId3,"String_Node_Str",null);
  long rawContactId4=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId4,"String_Node_Str",null);
  long rawContactId5=RawContactUtil.createRawContact(mResolver);
  DataUtil.insertStructuredName(mResolver,rawContactId5,"String_Node_Str",null);
  long contactId1=queryContactId(rawContactId1);
  long contactId2=queryContactId(rawContactId2);
  long contactId3=queryContactId(rawContactId3);
  assertEquals(contactId1,contactId2);
  assertSuggestions(queryContactId(rawContactId5),contactId1,contactId3);
}
Program: 152387
Project: 152387
Buggy source:
/** 
 * Find the set of matching raw contacts for given rawContactId. Add all the raw contact candidates with matching scores > threshold to RawContactMatchingCandidates. Keep doing this for every raw contact in RawContactMatchingCandidates until is it not changing.
 */
private RawContactMatchingCandidates findRawContactMatchingCandidates(SQLiteDatabase db,long rawContactId,MatchCandidateList candidates,RawContactMatcher matcher){
  updateMatchScoresForSuggestionsBasedOnDataMatches(db,rawContactId,candidates,matcher);
  final RawContactMatchingCandidates matchingCandidates=new RawContactMatchingCandidates(matcher.pickBestMatches(SCORE_THRESHOLD_SUGGEST));
  Set<Long> newIds=new HashSet<>();
  newIds.addAll(matchingCandidates.getRawContactIdSet());
  while (!newIds.isEmpty()) {
    final Set<Long> tmpIdSet=new HashSet<>();
    for (    long rId : newIds) {
      final RawContactMatcher rMatcher=new RawContactMatcher();
      updateMatchScoresForSuggestionsBasedOnDataMatches(db,rId,new MatchCandidateList(),rMatcher);
      List<MatchScore> newMatches=rMatcher.pickBestMatches(SCORE_THRESHOLD_SUGGEST);
      for (      MatchScore newMatch : newMatches) {
        final long newRawContactId=newMatch.getRawContactId();
        if (!matchingCandidates.getRawContactIdSet().contains(newRawContactId)) {
          tmpIdSet.add(newRawContactId);
          matchingCandidates.add(newMatch);
        }
      }
    }
    newIds.clear();
    newIds.addAll(tmpIdSet);
  }
  return matchingCandidates;
}

Fixed version (ground truth):
/** 
 * Find the set of matching raw contacts for given rawContactId. Add all the raw contact candidates with matching scores > threshold to RawContactMatchingCandidates. Keep doing this for every raw contact in RawContactMatchingCandidates until is it not changing.
 */
private RawContactMatchingCandidates findRawContactMatchingCandidates(SQLiteDatabase db,long rawContactId,MatchCandidateList candidates,RawContactMatcher matcher){
  updateMatchScores(db,rawContactId,candidates,matcher);
  final RawContactMatchingCandidates matchingCandidates=new RawContactMatchingCandidates(matcher.pickBestMatches());
  Set<Long> newIds=new HashSet<>();
  newIds.addAll(matchingCandidates.getRawContactIdSet());
  while (!newIds.isEmpty()) {
    final Set<Long> tmpIdSet=new HashSet<>();
    for (    long rId : newIds) {
      final RawContactMatcher rMatcher=new RawContactMatcher();
      updateMatchScores(db,rId,new MatchCandidateList(),rMatcher);
      List<MatchScore> newMatches=rMatcher.pickBestMatches();
      for (      MatchScore newMatch : newMatches) {
        final long newRawContactId=newMatch.getRawContactId();
        if (!matchingCandidates.getRawContactIdSet().contains(newRawContactId)) {
          tmpIdSet.add(newRawContactId);
          matchingCandidates.add(newMatch);
        }
      }
    }
    newIds.clear();
    newIds.addAll(tmpIdSet);
  }
  return matchingCandidates;
}
Program: 152390
Project: 152390
Buggy source:
/** 
 * Find out which mime-types are shared by more than one contacts for   {@code rawContactIds}. Clear the is_super_primary settings for these mime-types.  {@code rawContactIds} should be a comma separated ID list.
 */
private void clearSuperPrimarySetting(SQLiteDatabase db,String rawContactIds){
  final String sql="String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ RawContacts.CONTACT_ID+ "String_Node_Str"+ Tables.DATA+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ Data.RAW_CONTACT_ID+ "String_Node_Str"+ RawContacts._ID+ "String_Node_Str"+ Data.IS_SUPER_PRIMARY+ "String_Node_Str"+ Data.RAW_CONTACT_ID+ "String_Node_Str"+ rawContactIds+ "String_Node_Str"+ DataColumns.MIMETYPE_ID+ "String_Node_Str";
  int index=0;
  final StringBuilder mimeTypeCondition=new StringBuilder();
  mimeTypeCondition.append("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str");
  final Cursor c=db.rawQuery(sql,null);
  try {
    c.moveToPosition(-1);
    while (c.moveToNext()) {
      if (index > 0) {
        mimeTypeCondition.append(',');
      }
      mimeTypeCondition.append(c.getLong((0)));
      index++;
    }
  }
  finally {
    c.close();
  }
  if (index == 0) {
    return;
  }
  String superPrimaryUpdateSql="String_Node_Str" + Tables.DATA + "String_Node_Str"+ Data.IS_SUPER_PRIMARY+ "String_Node_Str"+ "String_Node_Str"+ Data.RAW_CONTACT_ID+ "String_Node_Str"+ RawContacts._ID+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ Data.RAW_CONTACT_ID+ "String_Node_Str"+ rawContactIds+ "String_Node_Str";
  mimeTypeCondition.append(')');
  superPrimaryUpdateSql+=mimeTypeCondition.toString();
  db.execSQL(superPrimaryUpdateSql,null);
}

Fixed version (ground truth):
/** 
 * Find out which mime-types are shared by more than one contacts for   {@code rawContactIds}. Clear the is_super_primary settings for these mime-types.  {@code rawContactIds} should be a comma separated ID list.
 */
private void clearSuperPrimarySetting(SQLiteDatabase db,String rawContactIds){
  final String sql="String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ Tables.DATA+ "String_Node_Str"+ Data.IS_SUPER_PRIMARY+ "String_Node_Str"+ Data.RAW_CONTACT_ID+ "String_Node_Str"+ rawContactIds+ "String_Node_Str"+ DataColumns.MIMETYPE_ID+ "String_Node_Str";
  int index=0;
  final StringBuilder mimeTypeCondition=new StringBuilder();
  mimeTypeCondition.append("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str");
  final Cursor c=db.rawQuery(sql,null);
  try {
    c.moveToPosition(-1);
    while (c.moveToNext()) {
      if (index > 0) {
        mimeTypeCondition.append(',');
      }
      mimeTypeCondition.append(c.getLong((0)));
      index++;
    }
  }
  finally {
    c.close();
  }
  if (index == 0) {
    return;
  }
  String superPrimaryUpdateSql="String_Node_Str" + Tables.DATA + "String_Node_Str"+ Data.IS_SUPER_PRIMARY+ "String_Node_Str"+ "String_Node_Str"+ Data.RAW_CONTACT_ID+ "String_Node_Str"+ rawContactIds+ "String_Node_Str";
  mimeTypeCondition.append(')');
  superPrimaryUpdateSql+=mimeTypeCondition.toString();
  db.execSQL(superPrimaryUpdateSql);
}
Program: 152391
Project: 152391
Buggy source:
/** 
 * Find the set of matching raw contacts for given rawContactId. Add all the raw contact candidates with matching scores > threshold to RawContactMatchingCandidates. Keep doing this for every raw contact in RawContactMatchingCandidates until is it not changing.
 */
private RawContactMatchingCandidates findRawContactMatchingCandidates(SQLiteDatabase db,long rawContactId,MatchCandidateList candidates,RawContactMatcher matcher){
  updateMatchScoresForSuggestionsBasedOnDataMatches(db,rawContactId,candidates,matcher);
  final RawContactMatchingCandidates matchingCandidates=new RawContactMatchingCandidates(matcher.pickBestMatches(SCORE_THRESHOLD_SUGGEST));
  Set<Long> newIds=new HashSet<>();
  newIds.addAll(matchingCandidates.getRawContactIdSet());
  while (!newIds.isEmpty()) {
    final Set<Long> tmpIdSet=new HashSet<>();
    for (    long rId : newIds) {
      final RawContactMatcher rMatcher=new RawContactMatcher();
      updateMatchScoresForSuggestionsBasedOnDataMatches(db,rId,new MatchCandidateList(),rMatcher);
      List<MatchScore> newMatches=rMatcher.pickBestMatches(SCORE_THRESHOLD_SUGGEST);
      for (      MatchScore newMatch : newMatches) {
        final long newRawContactId=newMatch.getRawContactId();
        if (!matchingCandidates.getRawContactIdSet().contains(newRawContactId)) {
          tmpIdSet.add(newRawContactId);
          matchingCandidates.add(newMatch);
        }
      }
    }
    newIds.clear();
    newIds.addAll(tmpIdSet);
  }
  return matchingCandidates;
}

Fixed version (ground truth):
/** 
 * Find the set of matching raw contacts for given rawContactId. Add all the raw contact candidates with matching scores > threshold to RawContactMatchingCandidates. Keep doing this for every raw contact in RawContactMatchingCandidates until is it not changing.
 */
private RawContactMatchingCandidates findRawContactMatchingCandidates(SQLiteDatabase db,long rawContactId,MatchCandidateList candidates,RawContactMatcher matcher){
  updateMatchScores(db,rawContactId,candidates,matcher);
  final RawContactMatchingCandidates matchingCandidates=new RawContactMatchingCandidates(matcher.pickBestMatches());
  Set<Long> newIds=new HashSet<>();
  newIds.addAll(matchingCandidates.getRawContactIdSet());
  while (!newIds.isEmpty()) {
    final Set<Long> tmpIdSet=new HashSet<>();
    for (    long rId : newIds) {
      final RawContactMatcher rMatcher=new RawContactMatcher();
      updateMatchScores(db,rId,new MatchCandidateList(),rMatcher);
      List<MatchScore> newMatches=rMatcher.pickBestMatches();
      for (      MatchScore newMatch : newMatches) {
        final long newRawContactId=newMatch.getRawContactId();
        if (!matchingCandidates.getRawContactIdSet().contains(newRawContactId)) {
          tmpIdSet.add(newRawContactId);
          matchingCandidates.add(newMatch);
        }
      }
    }
    newIds.clear();
    newIds.addAll(tmpIdSet);
  }
  return matchingCandidates;
}
Program: 152394
Project: 152394
Buggy source:
/** 
 * Find out which mime-types are shared by more than one contacts for   {@code rawContactIds}. Clear the is_super_primary settings for these mime-types.  {@code rawContactIds} should be a comma separated ID list.
 */
private void clearSuperPrimarySetting(SQLiteDatabase db,String rawContactIds){
  final String sql="String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ RawContacts.CONTACT_ID+ "String_Node_Str"+ Tables.DATA+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ Data.RAW_CONTACT_ID+ "String_Node_Str"+ RawContacts._ID+ "String_Node_Str"+ Data.IS_SUPER_PRIMARY+ "String_Node_Str"+ Data.RAW_CONTACT_ID+ "String_Node_Str"+ rawContactIds+ "String_Node_Str"+ DataColumns.MIMETYPE_ID+ "String_Node_Str";
  int index=0;
  final StringBuilder mimeTypeCondition=new StringBuilder();
  mimeTypeCondition.append("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str");
  final Cursor c=db.rawQuery(sql,null);
  try {
    c.moveToPosition(-1);
    while (c.moveToNext()) {
      if (index > 0) {
        mimeTypeCondition.append(',');
      }
      mimeTypeCondition.append(c.getLong((0)));
      index++;
    }
  }
  finally {
    c.close();
  }
  if (index == 0) {
    return;
  }
  String superPrimaryUpdateSql="String_Node_Str" + Tables.DATA + "String_Node_Str"+ Data.IS_SUPER_PRIMARY+ "String_Node_Str"+ "String_Node_Str"+ Data.RAW_CONTACT_ID+ "String_Node_Str"+ RawContacts._ID+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ Data.RAW_CONTACT_ID+ "String_Node_Str"+ rawContactIds+ "String_Node_Str";
  mimeTypeCondition.append(')');
  superPrimaryUpdateSql+=mimeTypeCondition.toString();
  db.execSQL(superPrimaryUpdateSql,null);
}

Fixed version (ground truth):
/** 
 * Find out which mime-types are shared by more than one contacts for   {@code rawContactIds}. Clear the is_super_primary settings for these mime-types.  {@code rawContactIds} should be a comma separated ID list.
 */
private void clearSuperPrimarySetting(SQLiteDatabase db,String rawContactIds){
  final String sql="String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ Tables.DATA+ "String_Node_Str"+ Data.IS_SUPER_PRIMARY+ "String_Node_Str"+ Data.RAW_CONTACT_ID+ "String_Node_Str"+ rawContactIds+ "String_Node_Str"+ DataColumns.MIMETYPE_ID+ "String_Node_Str";
  int index=0;
  final StringBuilder mimeTypeCondition=new StringBuilder();
  mimeTypeCondition.append("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str");
  final Cursor c=db.rawQuery(sql,null);
  try {
    c.moveToPosition(-1);
    while (c.moveToNext()) {
      if (index > 0) {
        mimeTypeCondition.append(',');
      }
      mimeTypeCondition.append(c.getLong((0)));
      index++;
    }
  }
  finally {
    c.close();
  }
  if (index == 0) {
    return;
  }
  String superPrimaryUpdateSql="String_Node_Str" + Tables.DATA + "String_Node_Str"+ Data.IS_SUPER_PRIMARY+ "String_Node_Str"+ "String_Node_Str"+ Data.RAW_CONTACT_ID+ "String_Node_Str"+ rawContactIds+ "String_Node_Str";
  mimeTypeCondition.append(')');
  superPrimaryUpdateSql+=mimeTypeCondition.toString();
  db.execSQL(superPrimaryUpdateSql);
}
Program: 152395
Project: 152395
Buggy source:
/** 
 * Find the set of matching raw contacts for given rawContactId. Add all the raw contact candidates with matching scores > threshold to RawContactMatchingCandidates. Keep doing this for every raw contact in RawContactMatchingCandidates until is it not changing.
 */
private RawContactMatchingCandidates findRawContactMatchingCandidates(SQLiteDatabase db,long rawContactId,MatchCandidateList candidates,RawContactMatcher matcher){
  updateMatchScoresForSuggestionsBasedOnDataMatches(db,rawContactId,candidates,matcher);
  final RawContactMatchingCandidates matchingCandidates=new RawContactMatchingCandidates(matcher.pickBestMatches(SCORE_THRESHOLD_SUGGEST));
  Set<Long> newIds=new HashSet<>();
  newIds.addAll(matchingCandidates.getRawContactIdSet());
  while (!newIds.isEmpty()) {
    final Set<Long> tmpIdSet=new HashSet<>();
    for (    long rId : newIds) {
      final RawContactMatcher rMatcher=new RawContactMatcher();
      updateMatchScoresForSuggestionsBasedOnDataMatches(db,rId,new MatchCandidateList(),rMatcher);
      List<MatchScore> newMatches=rMatcher.pickBestMatches(SCORE_THRESHOLD_SUGGEST);
      for (      MatchScore newMatch : newMatches) {
        final long newRawContactId=newMatch.getRawContactId();
        if (!matchingCandidates.getRawContactIdSet().contains(newRawContactId)) {
          tmpIdSet.add(newRawContactId);
          matchingCandidates.add(newMatch);
        }
      }
    }
    newIds.clear();
    newIds.addAll(tmpIdSet);
  }
  return matchingCandidates;
}

Fixed version (ground truth):
/** 
 * Find the set of matching raw contacts for given rawContactId. Add all the raw contact candidates with matching scores > threshold to RawContactMatchingCandidates. Keep doing this for every raw contact in RawContactMatchingCandidates until is it not changing.
 */
private RawContactMatchingCandidates findRawContactMatchingCandidates(SQLiteDatabase db,long rawContactId,MatchCandidateList candidates,RawContactMatcher matcher){
  updateMatchScores(db,rawContactId,candidates,matcher);
  final RawContactMatchingCandidates matchingCandidates=new RawContactMatchingCandidates(matcher.pickBestMatches());
  Set<Long> newIds=new HashSet<>();
  newIds.addAll(matchingCandidates.getRawContactIdSet());
  while (!newIds.isEmpty()) {
    final Set<Long> tmpIdSet=new HashSet<>();
    for (    long rId : newIds) {
      final RawContactMatcher rMatcher=new RawContactMatcher();
      updateMatchScores(db,rId,new MatchCandidateList(),rMatcher);
      List<MatchScore> newMatches=rMatcher.pickBestMatches();
      for (      MatchScore newMatch : newMatches) {
        final long newRawContactId=newMatch.getRawContactId();
        if (!matchingCandidates.getRawContactIdSet().contains(newRawContactId)) {
          tmpIdSet.add(newRawContactId);
          matchingCandidates.add(newMatch);
        }
      }
    }
    newIds.clear();
    newIds.addAll(tmpIdSet);
  }
  return matchingCandidates;
}