Program: 152480
Project: 152480
Buggy source:
/** 
 * Inserts a status update.
 */
public long insertStatusUpdate(ContentValues values){
  final String handle=values.getAsString(StatusUpdates.IM_HANDLE);
  final Integer protocol=values.getAsInteger(StatusUpdates.PROTOCOL);
  String customProtocol=null;
  if (protocol != null && protocol == Im.PROTOCOL_CUSTOM) {
    customProtocol=values.getAsString(StatusUpdates.CUSTOM_PROTOCOL);
    if (TextUtils.isEmpty(customProtocol)) {
      throw new IllegalArgumentException("String_Node_Str");
    }
  }
  long rawContactId=-1;
  long contactId=-1;
  Long dataId=values.getAsLong(StatusUpdates.DATA_ID);
  mSb.setLength(0);
  mSelectionArgs.clear();
  if (dataId != null) {
    mSb.append(Tables.DATA + "String_Node_Str" + Data._ID+ "String_Node_Str");
    mSelectionArgs.add(String.valueOf(dataId));
  }
 else {
    if (TextUtils.isEmpty(handle) || protocol == null) {
      throw new IllegalArgumentException("String_Node_Str");
    }
    boolean matchEmail=Im.PROTOCOL_GOOGLE_TALK == protocol;
    String mimeTypeIdIm=String.valueOf(mMimeTypeIdIm);
    if (matchEmail) {
      String mimeTypeIdEmail=String.valueOf(mMimeTypeIdEmail);
      mSb.append(DataColumns.MIMETYPE_ID + "String_Node_Str" + "String_Node_Str"+ Data.DATA1+ "String_Node_Str"+ "String_Node_Str"+ DataColumns.MIMETYPE_ID+ "String_Node_Str"+ Im.PROTOCOL+ "String_Node_Str");
      mSelectionArgs.add(mimeTypeIdEmail);
      mSelectionArgs.add(mimeTypeIdIm);
      mSelectionArgs.add(handle);
      mSelectionArgs.add(mimeTypeIdIm);
      mSelectionArgs.add(String.valueOf(protocol));
      if (customProtocol != null) {
        mSb.append("String_Node_Str" + Im.CUSTOM_PROTOCOL + "String_Node_Str");
        mSelectionArgs.add(customProtocol);
      }
      mSb.append("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str");
      mSelectionArgs.add(mimeTypeIdEmail);
    }
 else {
      mSb.append(DataColumns.MIMETYPE_ID + "String_Node_Str" + "String_Node_Str"+ Im.PROTOCOL+ "String_Node_Str"+ "String_Node_Str"+ Im.DATA+ "String_Node_Str");
      mSelectionArgs.add(mimeTypeIdIm);
      mSelectionArgs.add(String.valueOf(protocol));
      mSelectionArgs.add(handle);
      if (customProtocol != null) {
        mSb.append("String_Node_Str" + Im.CUSTOM_PROTOCOL + "String_Node_Str");
        mSelectionArgs.add(customProtocol);
      }
    }
    if (values.containsKey(StatusUpdates.DATA_ID)) {
      mSb.append("String_Node_Str" + DataColumns.CONCRETE_ID + "String_Node_Str");
      mSelectionArgs.add(values.getAsString(StatusUpdates.DATA_ID));
    }
  }
  mSb.append("String_Node_Str").append(getContactsRestrictions());
  Cursor cursor=null;
  try {
    cursor=mDb.query(DataContactsQuery.TABLE,DataContactsQuery.PROJECTION,mSb.toString(),mSelectionArgs.toArray(EMPTY_STRING_ARRAY),null,null,Clauses.CONTACT_VISIBLE + "String_Node_Str" + Data.RAW_CONTACT_ID);
    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();
    }
  }
  if (values.containsKey(StatusUpdates.PRESENCE)) {
    if (customProtocol == null) {
      customProtocol="String_Node_Str";
    }
    mValues.clear();
    mValues.put(StatusUpdates.DATA_ID,dataId);
    mValues.put(PresenceColumns.RAW_CONTACT_ID,rawContactId);
    mValues.put(PresenceColumns.CONTACT_ID,contactId);
    mValues.put(StatusUpdates.PROTOCOL,protocol);
    mValues.put(StatusUpdates.CUSTOM_PROTOCOL,customProtocol);
    mValues.put(StatusUpdates.IM_HANDLE,handle);
    if (values.containsKey(StatusUpdates.IM_ACCOUNT)) {
      mValues.put(StatusUpdates.IM_ACCOUNT,values.getAsString(StatusUpdates.IM_ACCOUNT));
    }
    mValues.put(StatusUpdates.PRESENCE,values.getAsString(StatusUpdates.PRESENCE));
    mValues.put(StatusUpdates.CHAT_CAPABILITY,values.getAsString(StatusUpdates.CHAT_CAPABILITY));
    mDb.replace(Tables.PRESENCE,null,mValues);
  }
  if (values.containsKey(StatusUpdates.STATUS)) {
    String status=values.getAsString(StatusUpdates.STATUS);
    String resPackage=values.getAsString(StatusUpdates.STATUS_RES_PACKAGE);
    Integer labelResource=values.getAsInteger(StatusUpdates.STATUS_LABEL);
    if (TextUtils.isEmpty(resPackage) && (labelResource == null || labelResource == 0) && protocol != null) {
      labelResource=Im.getProtocolLabelResource(protocol);
    }
    Long iconResource=values.getAsLong(StatusUpdates.STATUS_ICON);
    if (TextUtils.isEmpty(status)) {
      mStatusUpdateDelete.bindLong(1,dataId);
      mStatusUpdateDelete.execute();
    }
 else     if (values.containsKey(StatusUpdates.STATUS_TIMESTAMP)) {
      long timestamp=values.getAsLong(StatusUpdates.STATUS_TIMESTAMP);
      mStatusUpdateReplace.bindLong(1,dataId);
      mStatusUpdateReplace.bindLong(2,timestamp);
      bindString(mStatusUpdateReplace,3,status);
      bindString(mStatusUpdateReplace,4,resPackage);
      bindLong(mStatusUpdateReplace,5,iconResource);
      bindLong(mStatusUpdateReplace,6,labelResource);
      mStatusUpdateReplace.execute();
    }
 else {
      try {
        mStatusUpdateInsert.bindLong(1,dataId);
        bindString(mStatusUpdateInsert,2,status);
        bindString(mStatusUpdateInsert,3,resPackage);
        bindLong(mStatusUpdateInsert,4,iconResource);
        bindLong(mStatusUpdateInsert,5,labelResource);
        mStatusUpdateInsert.executeInsert();
      }
 catch (      SQLiteConstraintException e) {
        long timestamp=System.currentTimeMillis();
        mStatusUpdateAutoTimestamp.bindLong(1,timestamp);
        bindString(mStatusUpdateAutoTimestamp,2,status);
        mStatusUpdateAutoTimestamp.bindLong(3,dataId);
        bindString(mStatusUpdateAutoTimestamp,4,status);
        mStatusUpdateAutoTimestamp.execute();
        bindString(mStatusAttributionUpdate,1,resPackage);
        bindLong(mStatusAttributionUpdate,2,iconResource);
        bindLong(mStatusAttributionUpdate,3,labelResource);
        mStatusAttributionUpdate.bindLong(4,dataId);
        mStatusAttributionUpdate.execute();
      }
    }
  }
  if (contactId != -1) {
    mLastStatusUpdate.bindLong(1,contactId);
    mLastStatusUpdate.bindLong(2,contactId);
    mLastStatusUpdate.execute();
  }
  return dataId;
}

Fixed version (ground truth):
/** 
 * Inserts a status update.
 */
public long insertStatusUpdate(ContentValues values){
  final String handle=values.getAsString(StatusUpdates.IM_HANDLE);
  final Integer protocol=values.getAsInteger(StatusUpdates.PROTOCOL);
  String customProtocol=null;
  if (protocol != null && protocol == Im.PROTOCOL_CUSTOM) {
    customProtocol=values.getAsString(StatusUpdates.CUSTOM_PROTOCOL);
    if (TextUtils.isEmpty(customProtocol)) {
      throw new IllegalArgumentException("String_Node_Str");
    }
  }
  long rawContactId=-1;
  long contactId=-1;
  Long dataId=values.getAsLong(StatusUpdates.DATA_ID);
  mSb.setLength(0);
  mSelectionArgs.clear();
  if (dataId != null) {
    mSb.append(Tables.DATA + "String_Node_Str" + Data._ID+ "String_Node_Str");
    mSelectionArgs.add(String.valueOf(dataId));
  }
 else {
    if (TextUtils.isEmpty(handle) || protocol == null) {
      throw new IllegalArgumentException("String_Node_Str");
    }
    boolean matchEmail=Im.PROTOCOL_GOOGLE_TALK == protocol;
    String mimeTypeIdIm=String.valueOf(mMimeTypeIdIm);
    if (matchEmail) {
      String mimeTypeIdEmail=String.valueOf(mMimeTypeIdEmail);
      mSb.append(DataColumns.MIMETYPE_ID + "String_Node_Str" + "String_Node_Str"+ Data.DATA1+ "String_Node_Str"+ "String_Node_Str"+ DataColumns.MIMETYPE_ID+ "String_Node_Str"+ Im.PROTOCOL+ "String_Node_Str");
      mSelectionArgs.add(mimeTypeIdEmail);
      mSelectionArgs.add(mimeTypeIdIm);
      mSelectionArgs.add(handle);
      mSelectionArgs.add(mimeTypeIdIm);
      mSelectionArgs.add(String.valueOf(protocol));
      if (customProtocol != null) {
        mSb.append("String_Node_Str" + Im.CUSTOM_PROTOCOL + "String_Node_Str");
        mSelectionArgs.add(customProtocol);
      }
      mSb.append("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str");
      mSelectionArgs.add(mimeTypeIdEmail);
    }
 else {
      mSb.append(DataColumns.MIMETYPE_ID + "String_Node_Str" + "String_Node_Str"+ Im.PROTOCOL+ "String_Node_Str"+ "String_Node_Str"+ Im.DATA+ "String_Node_Str");
      mSelectionArgs.add(mimeTypeIdIm);
      mSelectionArgs.add(String.valueOf(protocol));
      mSelectionArgs.add(handle);
      if (customProtocol != null) {
        mSb.append("String_Node_Str" + Im.CUSTOM_PROTOCOL + "String_Node_Str");
        mSelectionArgs.add(customProtocol);
      }
    }
    if (values.containsKey(StatusUpdates.DATA_ID)) {
      mSb.append("String_Node_Str" + DataColumns.CONCRETE_ID + "String_Node_Str");
      mSelectionArgs.add(values.getAsString(StatusUpdates.DATA_ID));
    }
  }
  mSb.append("String_Node_Str").append(getContactsRestrictions());
  Cursor cursor=null;
  try {
    cursor=mDb.query(DataContactsQuery.TABLE,DataContactsQuery.PROJECTION,mSb.toString(),mSelectionArgs.toArray(EMPTY_STRING_ARRAY),null,null,Clauses.CONTACT_VISIBLE + "String_Node_Str" + Data.RAW_CONTACT_ID);
    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();
    }
  }
  if (values.containsKey(StatusUpdates.PRESENCE)) {
    if (customProtocol == null) {
      customProtocol="String_Node_Str";
    }
    mValues.clear();
    mValues.put(StatusUpdates.DATA_ID,dataId);
    mValues.put(PresenceColumns.RAW_CONTACT_ID,rawContactId);
    mValues.put(PresenceColumns.CONTACT_ID,contactId);
    mValues.put(StatusUpdates.PROTOCOL,protocol);
    mValues.put(StatusUpdates.CUSTOM_PROTOCOL,customProtocol);
    mValues.put(StatusUpdates.IM_HANDLE,handle);
    if (values.containsKey(StatusUpdates.IM_ACCOUNT)) {
      mValues.put(StatusUpdates.IM_ACCOUNT,values.getAsString(StatusUpdates.IM_ACCOUNT));
    }
    mValues.put(StatusUpdates.PRESENCE,values.getAsString(StatusUpdates.PRESENCE));
    mValues.put(StatusUpdates.CHAT_CAPABILITY,values.getAsString(StatusUpdates.CHAT_CAPABILITY));
    mDb.replace(Tables.PRESENCE,null,mValues);
  }
  if (values.containsKey(StatusUpdates.STATUS)) {
    String status=values.getAsString(StatusUpdates.STATUS);
    String resPackage=values.getAsString(StatusUpdates.STATUS_RES_PACKAGE);
    Integer labelResource=values.getAsInteger(StatusUpdates.STATUS_LABEL);
    if (TextUtils.isEmpty(resPackage) && (labelResource == null || labelResource == 0) && protocol != null) {
      labelResource=Im.getProtocolLabelResource(protocol);
    }
    Long iconResource=values.getAsLong(StatusUpdates.STATUS_ICON);
    if (TextUtils.isEmpty(status)) {
      mStatusUpdateDelete.bindLong(1,dataId);
      mStatusUpdateDelete.execute();
    }
 else     if (values.containsKey(StatusUpdates.STATUS_TIMESTAMP)) {
      long timestamp=values.getAsLong(StatusUpdates.STATUS_TIMESTAMP);
      mStatusUpdateReplace.bindLong(1,dataId);
      mStatusUpdateReplace.bindLong(2,timestamp);
      bindString(mStatusUpdateReplace,3,status);
      bindString(mStatusUpdateReplace,4,resPackage);
      bindLong(mStatusUpdateReplace,5,iconResource);
      bindLong(mStatusUpdateReplace,6,labelResource);
      mStatusUpdateReplace.execute();
    }
 else {
      try {
        mStatusUpdateInsert.bindLong(1,dataId);
        bindString(mStatusUpdateInsert,2,status);
        bindString(mStatusUpdateInsert,3,resPackage);
        bindLong(mStatusUpdateInsert,4,iconResource);
        bindLong(mStatusUpdateInsert,5,labelResource);
        mStatusUpdateInsert.executeInsert();
      }
 catch (      SQLiteConstraintException e) {
        long timestamp=System.currentTimeMillis();
        mStatusUpdateAutoTimestamp.bindLong(1,timestamp);
        bindString(mStatusUpdateAutoTimestamp,2,status);
        mStatusUpdateAutoTimestamp.bindLong(3,dataId);
        bindString(mStatusUpdateAutoTimestamp,4,status);
        mStatusUpdateAutoTimestamp.execute();
        bindString(mStatusAttributionUpdate,1,resPackage);
        bindLong(mStatusAttributionUpdate,2,iconResource);
        bindLong(mStatusAttributionUpdate,3,labelResource);
        mStatusAttributionUpdate.bindLong(4,dataId);
        mStatusAttributionUpdate.execute();
      }
    }
  }
  if (contactId != -1) {
    mContactAggregator.updateLastStatusUpdateId(contactId);
  }
  return dataId;
}