Program: 152520
Project: 152520
Buggy source:
/** 
 * Inserts a presence update.
 */
public long insertPresence(ContentValues values){
  final String handle=values.getAsString(Presence.IM_HANDLE);
  if (TextUtils.isEmpty(handle) || !values.containsKey(Presence.PROTOCOL)) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  final long protocol=values.getAsLong(Presence.PROTOCOL);
  String customProtocol=null;
  if (protocol == Im.PROTOCOL_CUSTOM) {
    customProtocol=values.getAsString(Presence.CUSTOM_PROTOCOL);
    if (TextUtils.isEmpty(customProtocol)) {
      throw new IllegalArgumentException("String_Node_Str");
    }
  }
  boolean matchEmail=Im.PROTOCOL_GOOGLE_TALK == protocol;
  StringBuilder selection=new StringBuilder();
  String[] selectionArgs;
  if (matchEmail) {
    selection.append("String_Node_Str" + MimetypesColumns.MIMETYPE + "String_Node_Str"+ Im.CONTENT_ITEM_TYPE+ "String_Node_Str"+ "String_Node_Str"+ Im.PROTOCOL+ "String_Node_Str"+ "String_Node_Str"+ Im.DATA+ "String_Node_Str");
    if (customProtocol != null) {
      selection.append("String_Node_Str" + Im.CUSTOM_PROTOCOL + "String_Node_Str");
      DatabaseUtils.appendEscapedSQLString(selection,customProtocol);
    }
    selection.append("String_Node_Str" + MimetypesColumns.MIMETYPE + "String_Node_Str"+ Email.CONTENT_ITEM_TYPE+ "String_Node_Str"+ "String_Node_Str"+ Email.DATA+ "String_Node_Str"+ "String_Node_Str");
    selectionArgs=new String[]{String.valueOf(protocol),handle,handle};
  }
 else {
    selection.append(MimetypesColumns.MIMETYPE + "String_Node_Str" + Im.CONTENT_ITEM_TYPE+ "String_Node_Str"+ "String_Node_Str"+ Im.PROTOCOL+ "String_Node_Str"+ "String_Node_Str"+ Im.DATA+ "String_Node_Str");
    if (customProtocol != null) {
      selection.append("String_Node_Str" + Im.CUSTOM_PROTOCOL + "String_Node_Str");
      DatabaseUtils.appendEscapedSQLString(selection,customProtocol);
    }
    selectionArgs=new String[]{String.valueOf(protocol),handle};
  }
  if (values.containsKey(Presence.DATA_ID)) {
    selection.append("String_Node_Str" + DataColumns.CONCRETE_ID + "String_Node_Str").append(values.getAsLong(Presence.DATA_ID));
  }
  selection.append("String_Node_Str").append(getContactsRestrictions());
  long dataId=-1;
  long rawContactId=-1;
  long contactId=-1;
  Cursor cursor=null;
  try {
    cursor=mDb.query(DataContactsQuery.TABLE,DataContactsQuery.PROJECTION,selection.toString(),selectionArgs,null,null,null);
    if (cursor.moveToFirst()) {
      dataId=cursor.getLong(DataContactsQuery.DATA_ID);
      rawContactId=cursor.getLong(DataContactsQuery.RAW_CONTACT_ID);
      contactId=cursor.getLong(DataContactsQuery.CONTACT_ID);
    }
 else {
      return -1;
    }
  }
  finally {
    if (cursor != null) {
      cursor.close();
    }
  }
  values.put(Presence.DATA_ID,dataId);
  values.put(PresenceColumns.RAW_CONTACT_ID,rawContactId);
  long presenceId=mDb.replace(Tables.PRESENCE,null,values);
  if (contactId != -1) {
    if (values.containsKey(Presence.PRESENCE_STATUS)) {
      mAggregatedPresenceReplace.bindLong(1,contactId);
      mAggregatedPresenceReplace.bindLong(2,contactId);
      mAggregatedPresenceReplace.execute();
    }
    String status=values.getAsString(Presence.PRESENCE_CUSTOM_STATUS);
    if (status != null) {
      mAggregatedPresenceStatusUpdate.bindString(1,status);
      mAggregatedPresenceStatusUpdate.bindLong(2,contactId);
      mAggregatedPresenceStatusUpdate.execute();
    }
  }
  return presenceId;
}

Fixed version (ground truth):
/** 
 * Inserts a presence update.
 */
public long insertPresence(ContentValues values){
  final String handle=values.getAsString(Presence.IM_HANDLE);
  if (TextUtils.isEmpty(handle) || !values.containsKey(Presence.PROTOCOL)) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  final long protocol=values.getAsLong(Presence.PROTOCOL);
  String customProtocol=null;
  if (protocol == Im.PROTOCOL_CUSTOM) {
    customProtocol=values.getAsString(Presence.CUSTOM_PROTOCOL);
    if (TextUtils.isEmpty(customProtocol)) {
      throw new IllegalArgumentException("String_Node_Str");
    }
  }
  boolean matchEmail=Im.PROTOCOL_GOOGLE_TALK == protocol;
  StringBuilder selection=new StringBuilder();
  String[] selectionArgs;
  if (matchEmail) {
    selection.append("String_Node_Str" + MimetypesColumns.MIMETYPE + "String_Node_Str"+ Im.CONTENT_ITEM_TYPE+ "String_Node_Str"+ "String_Node_Str"+ Im.PROTOCOL+ "String_Node_Str"+ "String_Node_Str"+ Im.DATA+ "String_Node_Str");
    if (customProtocol != null) {
      selection.append("String_Node_Str" + Im.CUSTOM_PROTOCOL + "String_Node_Str");
      DatabaseUtils.appendEscapedSQLString(selection,customProtocol);
    }
    selection.append("String_Node_Str" + MimetypesColumns.MIMETYPE + "String_Node_Str"+ Email.CONTENT_ITEM_TYPE+ "String_Node_Str"+ "String_Node_Str"+ Email.DATA+ "String_Node_Str"+ "String_Node_Str");
    selectionArgs=new String[]{String.valueOf(protocol),handle,handle};
  }
 else {
    selection.append(MimetypesColumns.MIMETYPE + "String_Node_Str" + Im.CONTENT_ITEM_TYPE+ "String_Node_Str"+ "String_Node_Str"+ Im.PROTOCOL+ "String_Node_Str"+ "String_Node_Str"+ Im.DATA+ "String_Node_Str");
    if (customProtocol != null) {
      selection.append("String_Node_Str" + Im.CUSTOM_PROTOCOL + "String_Node_Str");
      DatabaseUtils.appendEscapedSQLString(selection,customProtocol);
    }
    selectionArgs=new String[]{String.valueOf(protocol),handle};
  }
  if (values.containsKey(Presence.DATA_ID)) {
    selection.append("String_Node_Str" + DataColumns.CONCRETE_ID + "String_Node_Str").append(values.getAsLong(Presence.DATA_ID));
  }
  selection.append("String_Node_Str").append(getContactsRestrictions());
  long dataId=-1;
  long rawContactId=-1;
  long contactId=-1;
  Cursor cursor=null;
  try {
    cursor=mDb.query(DataContactsQuery.TABLE,DataContactsQuery.PROJECTION,selection.toString(),selectionArgs,null,null,null);
    if (cursor.moveToFirst()) {
      dataId=cursor.getLong(DataContactsQuery.DATA_ID);
      rawContactId=cursor.getLong(DataContactsQuery.RAW_CONTACT_ID);
      contactId=cursor.getLong(DataContactsQuery.CONTACT_ID);
    }
 else {
      return -1;
    }
  }
  finally {
    if (cursor != null) {
      cursor.close();
    }
  }
  values.put(Presence.DATA_ID,dataId);
  values.put(PresenceColumns.RAW_CONTACT_ID,rawContactId);
  if (customProtocol == null) {
    values.put(Presence.CUSTOM_PROTOCOL,"String_Node_Str");
  }
  long presenceId=mDb.replace(Tables.PRESENCE,null,values);
  if (contactId != -1) {
    if (values.containsKey(Presence.PRESENCE_STATUS)) {
      mAggregatedPresenceReplace.bindLong(1,contactId);
      mAggregatedPresenceReplace.bindLong(2,contactId);
      mAggregatedPresenceReplace.execute();
    }
    String status=values.getAsString(Presence.PRESENCE_CUSTOM_STATUS);
    if (status != null) {
      mAggregatedPresenceStatusUpdate.bindString(1,status);
      mAggregatedPresenceStatusUpdate.bindLong(2,contactId);
      mAggregatedPresenceStatusUpdate.execute();
    }
  }
  return presenceId;
}