Program: 152559
Project: 152559
Buggy source:
private int updateAggregationException(SQLiteDatabase db,ContentValues values){
  int exceptionType=values.getAsInteger(AggregationExceptions.TYPE);
  long aggregateId=values.getAsInteger(AggregationExceptions.AGGREGATE_ID);
  long contactId=values.getAsInteger(AggregationExceptions.CONTACT_ID);
  ArrayList<ContactPair> pairs=new ArrayList<ContactPair>();
  Cursor c=db.query(Tables.CONTACTS,CONTACT_PROJECTION,Contacts.AGGREGATE_ID + "String_Node_Str" + aggregateId,null,null,null,null);
  try {
    while (c.moveToNext()) {
      long aggregatedContactId=c.getLong(CONTACT_COLUMN_CONTACT_ID);
      if (aggregatedContactId != contactId) {
        pairs.add(new ContactPair(aggregatedContactId,contactId));
      }
    }
  }
  finally {
    c.close();
  }
  ContentValues exceptionValues=new ContentValues(3);
  exceptionValues.put(AggregationExceptions.TYPE,exceptionType);
  for (  ContactPair pair : pairs) {
    final String whereClause=AggregationExceptionColumns.CONTACT_ID1 + "String_Node_Str" + pair.contactId1+ "String_Node_Str"+ AggregationExceptionColumns.CONTACT_ID2+ "String_Node_Str"+ pair.contactId2;
    if (exceptionType == AggregationExceptions.TYPE_AUTOMATIC) {
      db.delete(Tables.AGGREGATION_EXCEPTIONS,whereClause,null);
    }
 else {
      exceptionValues.put(AggregationExceptionColumns.CONTACT_ID1,pair.contactId1);
      exceptionValues.put(AggregationExceptionColumns.CONTACT_ID2,pair.contactId2);
      db.replace(Tables.AGGREGATION_EXCEPTIONS,AggregationExceptions._ID,exceptionValues);
    }
  }
  mContactAggregator.markContactForAggregation(contactId);
  mContactAggregator.aggregateContact(contactId);
  return 1;
}

Fixed version (ground truth):
private int updateAggregationException(SQLiteDatabase db,ContentValues values){
  int exceptionType=values.getAsInteger(AggregationExceptions.TYPE);
  long aggregateId=values.getAsInteger(AggregationExceptions.AGGREGATE_ID);
  long contactId=values.getAsInteger(AggregationExceptions.CONTACT_ID);
  ArrayList<ContactPair> pairs=new ArrayList<ContactPair>();
  Cursor c=db.query(Tables.CONTACTS,CONTACT_PROJECTION,Contacts.AGGREGATE_ID + "String_Node_Str" + aggregateId,null,null,null,null);
  try {
    while (c.moveToNext()) {
      long aggregatedContactId=c.getLong(CONTACT_COLUMN_CONTACT_ID);
      if (aggregatedContactId != contactId) {
        pairs.add(new ContactPair(aggregatedContactId,contactId));
      }
    }
  }
  finally {
    c.close();
  }
  ContentValues exceptionValues=new ContentValues(3);
  exceptionValues.put(AggregationExceptions.TYPE,exceptionType);
  for (  ContactPair pair : pairs) {
    final String whereClause=AggregationExceptionColumns.CONTACT_ID1 + "String_Node_Str" + pair.contactId1+ "String_Node_Str"+ AggregationExceptionColumns.CONTACT_ID2+ "String_Node_Str"+ pair.contactId2;
    if (exceptionType == AggregationExceptions.TYPE_AUTOMATIC) {
      db.delete(Tables.AGGREGATION_EXCEPTIONS,whereClause,null);
    }
 else {
      exceptionValues.put(AggregationExceptionColumns.CONTACT_ID1,pair.contactId1);
      exceptionValues.put(AggregationExceptionColumns.CONTACT_ID2,pair.contactId2);
      db.replace(Tables.AGGREGATION_EXCEPTIONS,AggregationExceptions._ID,exceptionValues);
    }
  }
  mContactAggregator.markContactForAggregation(contactId);
  mContactAggregator.aggregateContact(contactId);
  if (exceptionType == AggregationExceptions.TYPE_AUTOMATIC || exceptionType == AggregationExceptions.TYPE_KEEP_OUT) {
    mContactAggregator.updateAggregateData(aggregateId);
  }
  return 1;
}