Program: 35542
Project: 35542
Buggy source:
private void processMessages(Response response,boolean isFromTheFuture){
  if (response.code() == 200) {
    ChatOverall chatOverall=(ChatOverall)response.body();
    List<ChatMessage> chatMessageList=chatOverall.getOcs().getData();
    if (isFirstMessagesProcessing) {
      isFirstMessagesProcessing=false;
      if (loadingProgressBar != null) {
        loadingProgressBar.setVisibility(View.GONE);
      }
      if (chatMessageList.size() == 0) {
        emptyLayout.setVisibility(View.VISIBLE);
      }
 else {
        messagesListView.setVisibility(View.VISIBLE);
      }
    }
 else {
      if (emptyLayout.getVisibility() != View.GONE) {
        emptyLayout.setVisibility(View.GONE);
      }
      if (messagesListView.getVisibility() != View.VISIBLE) {
        messagesListView.setVisibility(View.VISIBLE);
      }
    }
    int countGroupedMessages=0;
    if (!isFromTheFuture) {
      for (int i=0; i < chatMessageList.size(); i++) {
        if (chatMessageList.size() > i + 1) {
          if (chatMessageList.get(i + 1).getActorId().equals(chatMessageList.get(i).getActorId()) && countGroupedMessages < 4 && DateFormatter.isSameDay(chatMessageList.get(i).getCreatedAt(),chatMessageList.get(i + 1).getCreatedAt())) {
            chatMessageList.get(i).setGrouped(true);
            countGroupedMessages++;
          }
 else {
            countGroupedMessages=0;
          }
        }
        chatMessageList.get(i).setBaseUrl(conversationUser.getBaseUrl());
        if (globalLastKnownPastMessageId == -1 || chatMessageList.get(i).getJsonMessageId() < globalLastKnownPastMessageId) {
          globalLastKnownPastMessageId=chatMessageList.get(i).getJsonMessageId();
        }
        if (globalLastKnownFutureMessageId == -1) {
          if (chatMessageList.get(i).getJsonMessageId() > globalLastKnownFutureMessageId) {
            globalLastKnownFutureMessageId=chatMessageList.get(i).getJsonMessageId();
          }
        }
      }
      adapter.addToEnd(chatMessageList,false);
    }
 else {
      ChatMessage chatMessage;
      for (int i=0; i < chatMessageList.size(); i++) {
        chatMessage=chatMessageList.get(i);
        chatMessage.setBaseUrl(conversationUser.getBaseUrl());
        if (conversationUser.getUserId().equals("String_Node_Str") && !TextUtils.isEmpty(myFirstMessage.toString())) {
          if (chatMessage.getActorType().equals("String_Node_Str") && chatMessage.getActorDisplayName().equals(conversationUser.getDisplayName())) {
            conversationUser.setUserId(chatMessage.getActorId());
            setSenderId();
          }
        }
        boolean shouldScroll=layoutManager.findFirstVisibleItemPosition() == 0 || adapter.getItemCount() == 0;
        if (!shouldScroll && popupBubble != null) {
          if (!popupBubble.isShown()) {
            newMessagesCount=1;
            popupBubble.show();
          }
 else           if (popupBubble.isShown()) {
            newMessagesCount++;
          }
        }
 else {
          newMessagesCount=0;
        }
        chatMessage.setGrouped(adapter.isPreviousSameAuthor(chatMessage.getActorId(),-1) && (adapter.getSameAuthorLastMessagesCount(chatMessage.getActorId()) % 5) > 0);
        adapter.addToStart(chatMessage,shouldScroll);
      }
      String xChatLastGivenHeader;
      if (response.headers().size() > 0 && !TextUtils.isEmpty((xChatLastGivenHeader=response.headers().get("String_Node_Str")))) {
        globalLastKnownFutureMessageId=Integer.parseInt(xChatLastGivenHeader);
      }
    }
    if (!lookingIntoFuture && inChat) {
      pullChatMessages(1);
    }
  }
 else   if (response.code() == 304 && !isFromTheFuture) {
    if (isFirstMessagesProcessing) {
      isFirstMessagesProcessing=false;
      loadingProgressBar.setVisibility(View.GONE);
      if (emptyLayout.getVisibility() != View.VISIBLE) {
        emptyLayout.setVisibility(View.VISIBLE);
      }
    }
    historyRead=true;
    if (!lookingIntoFuture && inChat) {
      pullChatMessages(1);
    }
  }
}

Fixed version (ground truth):
private void processMessages(Response response,boolean isFromTheFuture){
  if (response.code() == 200) {
    ChatOverall chatOverall=(ChatOverall)response.body();
    List<ChatMessage> chatMessageList=chatOverall.getOcs().getData();
    if (isFirstMessagesProcessing) {
      isFirstMessagesProcessing=false;
      if (loadingProgressBar != null) {
        loadingProgressBar.setVisibility(View.GONE);
      }
      if (chatMessageList.size() == 0) {
        if (emptyLayout != null) {
          emptyLayout.setVisibility(View.VISIBLE);
        }
      }
 else {
        if (messagesListView != null) {
          messagesListView.setVisibility(View.VISIBLE);
        }
      }
    }
 else {
      if (emptyLayout.getVisibility() != View.GONE) {
        emptyLayout.setVisibility(View.GONE);
      }
      if (messagesListView.getVisibility() != View.VISIBLE) {
        messagesListView.setVisibility(View.VISIBLE);
      }
    }
    int countGroupedMessages=0;
    if (!isFromTheFuture) {
      for (int i=0; i < chatMessageList.size(); i++) {
        if (chatMessageList.size() > i + 1) {
          if (chatMessageList.get(i + 1).getActorId().equals(chatMessageList.get(i).getActorId()) && countGroupedMessages < 4 && DateFormatter.isSameDay(chatMessageList.get(i).getCreatedAt(),chatMessageList.get(i + 1).getCreatedAt())) {
            chatMessageList.get(i).setGrouped(true);
            countGroupedMessages++;
          }
 else {
            countGroupedMessages=0;
          }
        }
        chatMessageList.get(i).setBaseUrl(conversationUser.getBaseUrl());
        if (globalLastKnownPastMessageId == -1 || chatMessageList.get(i).getJsonMessageId() < globalLastKnownPastMessageId) {
          globalLastKnownPastMessageId=chatMessageList.get(i).getJsonMessageId();
        }
        if (globalLastKnownFutureMessageId == -1) {
          if (chatMessageList.get(i).getJsonMessageId() > globalLastKnownFutureMessageId) {
            globalLastKnownFutureMessageId=chatMessageList.get(i).getJsonMessageId();
          }
        }
      }
      adapter.addToEnd(chatMessageList,false);
    }
 else {
      ChatMessage chatMessage;
      for (int i=0; i < chatMessageList.size(); i++) {
        chatMessage=chatMessageList.get(i);
        chatMessage.setBaseUrl(conversationUser.getBaseUrl());
        if (conversationUser.getUserId().equals("String_Node_Str") && !TextUtils.isEmpty(myFirstMessage.toString())) {
          if (chatMessage.getActorType().equals("String_Node_Str") && chatMessage.getActorDisplayName().equals(conversationUser.getDisplayName())) {
            conversationUser.setUserId(chatMessage.getActorId());
            setSenderId();
          }
        }
        boolean shouldScroll=layoutManager.findFirstVisibleItemPosition() == 0 || adapter.getItemCount() == 0;
        if (!shouldScroll && popupBubble != null) {
          if (!popupBubble.isShown()) {
            newMessagesCount=1;
            popupBubble.show();
          }
 else           if (popupBubble.isShown()) {
            newMessagesCount++;
          }
        }
 else {
          newMessagesCount=0;
        }
        chatMessage.setGrouped(adapter.isPreviousSameAuthor(chatMessage.getActorId(),-1) && (adapter.getSameAuthorLastMessagesCount(chatMessage.getActorId()) % 5) > 0);
        adapter.addToStart(chatMessage,shouldScroll);
      }
      String xChatLastGivenHeader;
      if (response.headers().size() > 0 && !TextUtils.isEmpty((xChatLastGivenHeader=response.headers().get("String_Node_Str")))) {
        globalLastKnownFutureMessageId=Integer.parseInt(xChatLastGivenHeader);
      }
    }
    if (!lookingIntoFuture && inChat) {
      pullChatMessages(1);
    }
  }
 else   if (response.code() == 304 && !isFromTheFuture) {
    if (isFirstMessagesProcessing) {
      isFirstMessagesProcessing=false;
      loadingProgressBar.setVisibility(View.GONE);
      if (emptyLayout.getVisibility() != View.VISIBLE) {
        emptyLayout.setVisibility(View.VISIBLE);
      }
    }
    historyRead=true;
    if (!lookingIntoFuture && inChat) {
      pullChatMessages(1);
    }
  }
}