Program: 152532
Project: 152532
Buggy source:
/** 
 * Given a specific raw contact, finds all matching aggregate contacts and chooses the one with the highest match score.  If no such contact is found, creates a new contact.
 */
private synchronized void aggregateContact(SQLiteDatabase db,long rawContactId,long currentContactId,MatchCandidateList candidates,ContactMatcher matcher,ContentValues values){
  mRawContactsMarkedForAggregation.remove(rawContactId);
  candidates.clear();
  matcher.clear();
  long contactId=pickBestMatchBasedOnExceptions(db,rawContactId,matcher);
  if (contactId == -1) {
    contactId=pickBestMatchBasedOnData(db,rawContactId,candidates,matcher);
  }
  long currentContactContentsCount=0;
  if (currentContactId != 0) {
    mRawContactCountQuery.bindLong(1,currentContactId);
    mRawContactCountQuery.bindLong(2,rawContactId);
    currentContactContentsCount=mRawContactCountQuery.simpleQueryForLong();
  }
  if (contactId == -1 && currentContactId != 0 && currentContactContentsCount == 0) {
    contactId=currentContactId;
  }
  if (contactId != currentContactId && currentContactContentsCount == 0) {
    mContactDelete.bindLong(1,currentContactId);
    mContactDelete.execute();
  }
  if (contactId == -1) {
    ContentValues contactValues=new ContentValues();
    contactValues.put(RawContactsColumns.DISPLAY_NAME,"String_Node_Str");
    computeAggregateData(db,RawContactsColumns.CONCRETE_ID + "String_Node_Str" + rawContactId,contactValues);
    contactId=db.insert(Tables.CONTACTS,Contacts.DISPLAY_NAME,contactValues);
    mOpenHelper.setContactIdAndMarkAggregated(rawContactId,contactId);
    mOpenHelper.updateContactVisible(contactId);
  }
 else {
    mOpenHelper.setContactIdAndMarkAggregated(rawContactId,contactId);
    computeAggregateData(db,RawContacts.CONTACT_ID + "String_Node_Str" + contactId,values);
    db.update(Tables.CONTACTS,values,Contacts._ID + "String_Node_Str" + contactId,null);
    mOpenHelper.updateContactVisible(contactId);
  }
}

Fixed version (ground truth):
/** 
 * Given a specific raw contact, finds all matching aggregate contacts and chooses the one with the highest match score.  If no such contact is found, creates a new contact.
 */
private synchronized void aggregateContact(SQLiteDatabase db,long rawContactId,long currentContactId,MatchCandidateList candidates,ContactMatcher matcher,ContentValues values){
  mRawContactsMarkedForAggregation.remove(rawContactId);
  candidates.clear();
  matcher.clear();
  long contactId=pickBestMatchBasedOnExceptions(db,rawContactId,matcher);
  if (contactId == -1) {
    contactId=pickBestMatchBasedOnData(db,rawContactId,candidates,matcher);
  }
  long currentContactContentsCount=0;
  if (currentContactId != 0) {
    mRawContactCountQuery.bindLong(1,currentContactId);
    mRawContactCountQuery.bindLong(2,rawContactId);
    currentContactContentsCount=mRawContactCountQuery.simpleQueryForLong();
  }
  if (contactId == -1 && currentContactId != 0 && currentContactContentsCount == 0) {
    contactId=currentContactId;
  }
  if (contactId != currentContactId && currentContactContentsCount == 0) {
    mContactDelete.bindLong(1,currentContactId);
    mContactDelete.execute();
  }
  if (contactId == -1) {
    ContentValues contactValues=new ContentValues();
    contactValues.put(RawContactsColumns.DISPLAY_NAME,"String_Node_Str");
    computeAggregateData(db,RawContactsColumns.CONCRETE_ID + "String_Node_Str" + rawContactId,contactValues);
    contactId=db.insert(Tables.CONTACTS,Contacts.DISPLAY_NAME,contactValues);
    mOpenHelper.setContactIdAndMarkAggregated(rawContactId,contactId);
    mOpenHelper.updateContactVisible(contactId);
  }
 else {
    mOpenHelper.setContactIdAndMarkAggregated(rawContactId,contactId);
    computeAggregateData(db,contactId,values);
    db.update(Tables.CONTACTS,values,Contacts._ID + "String_Node_Str" + contactId,null);
    mOpenHelper.updateContactVisible(contactId);
  }
}