Program: 114300
Project: 114300
Buggy source:
public static void saveChatMessage(Context context,MessageCache messageCache,boolean fromHistory){
  int countUnreadMessagesLocal;
  boolean ownMessage=AppSession.getSession().getUser().getId() == messageCache.getSenderId();
  ContentValues values=new ContentValues();
  String condition=MessageTable.Cols.MESSAGE_ID + "String_Node_Str" + messageCache.getId()+ "String_Node_Str";
  ContentResolver resolver=context.getContentResolver();
  Cursor cursor=resolver.query(MessageTable.CONTENT_URI,null,condition,null,null);
  String body;
  if (messageCache.getMessagesNotificationType() != null) {
    values.put(MessageTable.Cols.FRIENDS_NOTIFICATION_TYPE,messageCache.getMessagesNotificationType().getCode());
  }
  body=parseMessageBody(context,messageCache);
  values.put(MessageTable.Cols.BODY,body);
  values.put(MessageTable.Cols.TIME,messageCache.getTime());
  values.put(MessageTable.Cols.ATTACH_FILE_ID,messageCache.getAttachUrl());
  values.put(MessageTable.Cols.IS_READ,messageCache.isRead());
  values.put(MessageTable.Cols.IS_DELIVERED,messageCache.isDelivered());
  values.put(MessageTable.Cols.IS_SYNC,messageCache.isSync());
  if (cursor != null && cursor.getCount() > ConstsCore.ZERO_INT_VALUE) {
    resolver.update(MessageTable.CONTENT_URI,values,condition,null);
  }
 else {
    values.put(MessageTable.Cols.MESSAGE_ID,messageCache.getId());
    values.put(MessageTable.Cols.DIALOG_ID,messageCache.getDialogId());
    values.put(MessageTable.Cols.SENDER_ID,messageCache.getSenderId());
    resolver.insert(MessageTable.CONTENT_URI,values);
  }
  if (fromHistory) {
    countUnreadMessagesLocal=ConstsCore.ZERO_INT_VALUE;
  }
 else   if (!messageCache.isSync() && !ownMessage) {
    countUnreadMessagesLocal=getCountUnreadMessagesByDialogIdLocal(context,messageCache.getDialogId());
    countUnreadMessagesLocal=++countUnreadMessagesLocal;
  }
 else {
    countUnreadMessagesLocal=getCountUnreadMessagesByDialogIdLocal(context,messageCache.getDialogId());
  }
  updateDialog(context,messageCache.getDialogId(),body,messageCache.getTime(),messageCache.getSenderId(),countUnreadMessagesLocal);
}

Fixed version (ground truth):
private static void saveChatMessage(Context context,MessageCache messageCache){
  ContentValues values=new ContentValues();
  MessagesNotificationType messagesNotificationType=messageCache.getMessagesNotificationType();
  messageCache.setMessage(parseMessageBody(context,messageCache));
  values.put(MessageTable.Cols.BODY,messageCache.getMessage());
  values.put(MessageTable.Cols.TIME,messageCache.getTime());
  values.put(MessageTable.Cols.ATTACH_FILE_ID,messageCache.getAttachUrl());
  values.put(MessageTable.Cols.IS_READ,messageCache.isRead());
  values.put(MessageTable.Cols.IS_DELIVERED,messageCache.isDelivered());
  values.put(MessageTable.Cols.IS_SYNC,messageCache.isSync());
  values.put(MessageTable.Cols.FRIENDS_NOTIFICATION_TYPE,messagesNotificationType == null ? ConstsCore.ZERO_INT_VALUE : messagesNotificationType.getCode());
  String condition=MessageTable.Cols.MESSAGE_ID + "String_Node_Str" + messageCache.getId()+ "String_Node_Str";
  ContentResolver resolver=context.getContentResolver();
  Cursor cursor=resolver.query(MessageTable.CONTENT_URI,null,condition,null,null);
  if (cursor != null && cursor.getCount() > ConstsCore.ZERO_INT_VALUE) {
    resolver.update(MessageTable.CONTENT_URI,values,condition,null);
  }
 else {
    values.put(MessageTable.Cols.MESSAGE_ID,messageCache.getId());
    values.put(MessageTable.Cols.DIALOG_ID,messageCache.getDialogId());
    values.put(MessageTable.Cols.SENDER_ID,messageCache.getSenderId());
    resolver.insert(MessageTable.CONTENT_URI,values);
  }
}