Program: 32032
Project: 32032
Buggy source:
private void saveRoomMessages(String roomId){
  LinkedHashMap<String,Event> eventsHash=mRoomEvents.get(roomId);
  String token=mRoomTokens.get(roomId);
  if ((null != eventsHash) && (null != token)) {
    LinkedHashMap<String,Event> hashCopy=new LinkedHashMap<>();
    ArrayList<Event> eventsList=new ArrayList<>(eventsHash.values());
    int startIndex=0;
    if (eventsList.size() > MAX_STORED_MESSAGES_COUNT) {
      startIndex=eventsList.size() - MAX_STORED_MESSAGES_COUNT;
      for (; !eventsList.get(startIndex).hasToken() && (startIndex > 0); startIndex--)       ;
      if ((eventsList.size() - startIndex) > (2 * MAX_STORED_MESSAGES_COUNT)) {
        Log.d(LOG_TAG,"String_Node_Str" + roomId + "String_Node_Str");
        startIndex=eventsList.size() - 10;
        for (; !eventsList.get(startIndex).hasToken() && (startIndex > 0); startIndex--)         ;
      }
      if (startIndex > 0) {
        Log.d(LOG_TAG,"String_Node_Str" + roomId + "String_Node_Str"+ eventsList.size()+ "String_Node_Str"+ (eventsList.size() - startIndex));
      }
    }
    long t0=System.currentTimeMillis();
    for (int index=startIndex; index < eventsList.size(); index++) {
      Event event=eventsList.get(index);
      event.prepareSerialization();
      hashCopy.put(event.eventId,event);
    }
    if (!writeObject("String_Node_Str" + roomId,new File(mGzStoreRoomsMessagesFolderFile,roomId),hashCopy)) {
      return;
    }
    if (!writeObject("String_Node_Str" + roomId,new File(mStoreRoomsTokensFolderFile,roomId),token)) {
      return;
    }
    Log.d(LOG_TAG,"String_Node_Str" + roomId + "String_Node_Str"+ eventsList.size()+ "String_Node_Str"+ (System.currentTimeMillis() - t0)+ "String_Node_Str");
  }
 else {
    deleteRoomMessagesFiles(roomId);
  }
}

Fixed version (ground truth):
private void saveRoomMessages(String roomId){
  LinkedHashMap<String,Event> eventsHash;
synchronized (mRoomEventsLock) {
    eventsHash=mRoomEvents.get(roomId);
  }
  String token=mRoomTokens.get(roomId);
  if ((null != eventsHash) && (null != token)) {
    LinkedHashMap<String,Event> hashCopy=new LinkedHashMap<>();
    ArrayList<Event> eventsList;
synchronized (mRoomEventsLock) {
      eventsList=new ArrayList<>(eventsHash.values());
    }
    int startIndex=0;
    if (eventsList.size() > MAX_STORED_MESSAGES_COUNT) {
      startIndex=eventsList.size() - MAX_STORED_MESSAGES_COUNT;
      for (; !eventsList.get(startIndex).hasToken() && (startIndex > 0); startIndex--)       ;
      if ((eventsList.size() - startIndex) > (2 * MAX_STORED_MESSAGES_COUNT)) {
        Log.d(LOG_TAG,"String_Node_Str" + roomId + "String_Node_Str");
        startIndex=eventsList.size() - 10;
        for (; !eventsList.get(startIndex).hasToken() && (startIndex > 0); startIndex--)         ;
      }
      if (startIndex > 0) {
        Log.d(LOG_TAG,"String_Node_Str" + roomId + "String_Node_Str"+ eventsList.size()+ "String_Node_Str"+ (eventsList.size() - startIndex));
      }
    }
    long t0=System.currentTimeMillis();
    for (int index=startIndex; index < eventsList.size(); index++) {
      Event event=eventsList.get(index);
      event.prepareSerialization();
      hashCopy.put(event.eventId,event);
    }
    if (!writeObject("String_Node_Str" + roomId,new File(mGzStoreRoomsMessagesFolderFile,roomId),hashCopy)) {
      return;
    }
    if (!writeObject("String_Node_Str" + roomId,new File(mStoreRoomsTokensFolderFile,roomId),token)) {
      return;
    }
    Log.d(LOG_TAG,"String_Node_Str" + roomId + "String_Node_Str"+ eventsList.size()+ "String_Node_Str"+ (System.currentTimeMillis() - t0)+ "String_Node_Str");
  }
 else {
    deleteRoomMessagesFiles(roomId);
  }
}