Program: 32163
Project: 32163
Buggy source:
public void handleJoinedRoomSync(RoomSync roomSync,boolean isInitialSync){
  RoomState liveState=getLiveState();
  String membership=null;
  RoomSummary currentSummary=null;
  mIsV2Syncing=true;
  RoomMember selfMember=liveState.getMember(mMyUserId);
  if (null != selfMember) {
    membership=selfMember.membership;
  }
  boolean isRoomInitialSync=(null == membership) || TextUtils.equals(membership,RoomMember.MEMBERSHIP_INVITE);
  if (TextUtils.equals(membership,RoomMember.MEMBERSHIP_INVITE)) {
    Log.d(LOG_TAG,"String_Node_Str" + mRoomId);
    mDataHandler.getStore().deleteRoomData(mRoomId);
    RoomState state=new RoomState();
    state.roomId=mRoomId;
    state.setDataHandler(mDataHandler);
    this.mBackState=this.mLiveState=state;
  }
  if ((null != roomSync.state) && (null != roomSync.state.events) && (roomSync.state.events.size() > 0)) {
    processLiveState(roomSync.state.events);
    if (isRoomInitialSync) {
      this.mBackState=this.mLiveState.deepCopy();
    }
  }
  if (null != roomSync.timeline) {
    if (roomSync.timeline.limited) {
      if (!isRoomInitialSync) {
        currentSummary=mDataHandler.getStore().getSummary(mRoomId);
        Event oldestEvent=mDataHandler.getStore().getOldestEvent(mRoomId);
        mDataHandler.getStore().deleteAllRoomMessages(mRoomId,true);
        if (oldestEvent != null) {
          if (RoomSummary.isSupportedEvent(oldestEvent)) {
            mDataHandler.getStore().storeSummary(oldestEvent.roomId,oldestEvent,getLiveState(),mMyUserId);
          }
        }
      }
      mDataHandler.getStore().storeBackToken(mRoomId,roomSync.timeline.prevBatch);
      mBackState.setToken(null);
      canStillPaginate=true;
    }
    if ((null != roomSync.timeline.events) && (roomSync.timeline.events.size() > 0)) {
      List<Event> events=roomSync.timeline.events;
      for (      Event event : events) {
        event.roomId=mRoomId;
        try {
          mDataHandler.handleLiveEvent(event,!isInitialSync && !isRoomInitialSync);
        }
 catch (        Exception e) {
          Log.e(LOG_TAG,"String_Node_Str" + e.getLocalizedMessage());
        }
      }
    }
    if (roomSync.timeline.limited) {
      Collection<Event> events=mDataHandler.getStore().getRoomMessages(mRoomId);
      if (null != events) {
        ArrayList<Event> unsentEvents=new ArrayList<Event>();
        for (        Event event : events) {
          if (event.mSentState != Event.SentState.SENT) {
            unsentEvents.add(event);
          }
        }
        if (unsentEvents.size() > 0) {
          for (          Event event : unsentEvents) {
            event.mSentState=Event.SentState.UNDELIVERABLE;
            event.originServerTs=System.currentTimeMillis();
            mDataHandler.getStore().deleteEvent(event);
            mDataHandler.getStore().storeLiveRoomEvent(event);
          }
          mDataHandler.getStore().commit();
        }
      }
    }
  }
  if (isRoomInitialSync) {
    mIsReady=true;
  }
 else {
    if ((null != roomSync.timeline) && roomSync.timeline.limited) {
      mDataHandler.onRoomSyncWithLimitedTimeline(mRoomId);
    }
  }
  if ((null != roomSync.ephemeral) && (null != roomSync.ephemeral.events)) {
    for (    Event event : roomSync.ephemeral.events) {
      event.roomId=mRoomId;
      try {
        mDataHandler.handleLiveEvent(event,!isInitialSync && !isRoomInitialSync);
      }
 catch (      Exception e) {
        Log.e(LOG_TAG,"String_Node_Str" + e.getLocalizedMessage());
      }
    }
  }
  if (null != roomSync.accountData) {
    handleAccountDataEvents(roomSync.accountData.events);
  }
  selfMember=liveState.getMember(mMyUserId);
  if (null != selfMember) {
    membership=selfMember.membership;
    if (TextUtils.equals(membership,RoomMember.MEMBERSHIP_LEAVE) || TextUtils.equals(membership,RoomMember.MEMBERSHIP_BAN)) {
      if (null != mDataHandler.getStore().getRoom(mRoomId)) {
        mDataHandler.getStore().deleteRoom(mRoomId);
        mDataHandler.onLeaveRoom(mRoomId);
      }
    }
  }
  if (null != mDataHandler.getStore().getRoom(mRoomId)) {
    RoomSummary summary=mDataHandler.getStore().getSummary(mRoomId);
    if (null == summary) {
      Event oldestEvent=mDataHandler.getStore().getOldestEvent(mRoomId);
      if (oldestEvent != null) {
        if (RoomSummary.isSupportedEvent(oldestEvent)) {
          mDataHandler.getStore().storeSummary(oldestEvent.roomId,oldestEvent,getLiveState(),mMyUserId);
          mDataHandler.getStore().commit();
        }
      }
 else       if (null != currentSummary) {
        mDataHandler.getStore().storeSummary(mRoomId,currentSummary.getLatestEvent(),getLiveState(),mMyUserId);
        mDataHandler.getStore().commit();
      }
 else       if ((null != roomSync.state) && (null != roomSync.state.events) && (roomSync.state.events.size() > 0)) {
        ArrayList<Event> events=new ArrayList<Event>(roomSync.state.events);
        Collections.reverse(events);
        for (        Event event : events) {
          event.roomId=mRoomId;
          if (RoomSummary.isSupportedEvent(event)) {
            summary=mDataHandler.getStore().storeSummary(event.roomId,event,getLiveState(),mMyUserId);
            if (Event.EVENT_TYPE_STATE_ROOM_NAME.equals(event.type) || Event.EVENT_TYPE_STATE_ROOM_ALIASES.equals(event.type) || Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(event.type)) {
              if (null != summary) {
                summary.setName(getName(mMyUserId));
              }
            }
            mDataHandler.getStore().commit();
            break;
          }
        }
      }
    }
  }
  if (null != mOnInitialSyncCallback) {
    try {
      mOnInitialSyncCallback.onSuccess(null);
    }
 catch (    Exception e) {
    }
    mOnInitialSyncCallback=null;
  }
  if (null != roomSync.unreadNotifications) {
    int notifCount=0;
    int highlightCount=0;
    if (null != roomSync.unreadNotifications.highlightCount) {
      highlightCount=roomSync.unreadNotifications.highlightCount;
    }
    if (null != roomSync.unreadNotifications.notificationCount) {
      notifCount=roomSync.unreadNotifications.notificationCount;
    }
    boolean isUpdated=(notifCount != getLiveState().mNotificationCount) || (getLiveState().mHighlightCount != highlightCount);
    if (isUpdated) {
      getLiveState().mNotificationCount=notifCount;
      getLiveState().mHighlightCount=highlightCount;
      mDataHandler.getStore().storeLiveStateForRoom(mRoomId);
    }
  }
  mIsV2Syncing=false;
}

Fixed version (ground truth):
public void handleJoinedRoomSync(RoomSync roomSync,boolean isInitialSync){
  String membership=null;
  RoomSummary currentSummary=null;
  mIsV2Syncing=true;
  RoomMember selfMember=getLiveState().getMember(mMyUserId);
  if (null != selfMember) {
    membership=selfMember.membership;
  }
  boolean isRoomInitialSync=(null == membership) || TextUtils.equals(membership,RoomMember.MEMBERSHIP_INVITE);
  if (TextUtils.equals(membership,RoomMember.MEMBERSHIP_INVITE)) {
    Log.d(LOG_TAG,"String_Node_Str" + mRoomId);
    mDataHandler.getStore().deleteRoomData(mRoomId);
    RoomState state=new RoomState();
    state.roomId=mRoomId;
    state.setDataHandler(mDataHandler);
    this.mBackState=this.mLiveState=state;
  }
  if ((null != roomSync.state) && (null != roomSync.state.events) && (roomSync.state.events.size() > 0)) {
    processLiveState(roomSync.state.events);
    if (isRoomInitialSync) {
      this.mBackState=this.mLiveState.deepCopy();
    }
  }
  if (null != roomSync.timeline) {
    if (roomSync.timeline.limited) {
      if (!isRoomInitialSync) {
        currentSummary=mDataHandler.getStore().getSummary(mRoomId);
        Event oldestEvent=mDataHandler.getStore().getOldestEvent(mRoomId);
        mDataHandler.getStore().deleteAllRoomMessages(mRoomId,true);
        if (oldestEvent != null) {
          if (RoomSummary.isSupportedEvent(oldestEvent)) {
            mDataHandler.getStore().storeSummary(oldestEvent.roomId,oldestEvent,getLiveState(),mMyUserId);
          }
        }
      }
      mDataHandler.getStore().storeBackToken(mRoomId,roomSync.timeline.prevBatch);
      mBackState.setToken(null);
      canStillPaginate=true;
    }
    if ((null != roomSync.timeline.events) && (roomSync.timeline.events.size() > 0)) {
      List<Event> events=roomSync.timeline.events;
      for (      Event event : events) {
        event.roomId=mRoomId;
        try {
          mDataHandler.handleLiveEvent(event,!isInitialSync && !isRoomInitialSync);
        }
 catch (        Exception e) {
          Log.e(LOG_TAG,"String_Node_Str" + e.getLocalizedMessage());
        }
      }
    }
    if (roomSync.timeline.limited) {
      Collection<Event> events=mDataHandler.getStore().getRoomMessages(mRoomId);
      if (null != events) {
        ArrayList<Event> unsentEvents=new ArrayList<Event>();
        for (        Event event : events) {
          if (event.mSentState != Event.SentState.SENT) {
            unsentEvents.add(event);
          }
        }
        if (unsentEvents.size() > 0) {
          for (          Event event : unsentEvents) {
            event.mSentState=Event.SentState.UNDELIVERABLE;
            event.originServerTs=System.currentTimeMillis();
            mDataHandler.getStore().deleteEvent(event);
            mDataHandler.getStore().storeLiveRoomEvent(event);
          }
          mDataHandler.getStore().commit();
        }
      }
    }
  }
  if (isRoomInitialSync) {
    mIsReady=true;
  }
 else {
    if ((null != roomSync.timeline) && roomSync.timeline.limited) {
      mDataHandler.onRoomSyncWithLimitedTimeline(mRoomId);
    }
  }
  if ((null != roomSync.ephemeral) && (null != roomSync.ephemeral.events)) {
    for (    Event event : roomSync.ephemeral.events) {
      event.roomId=mRoomId;
      try {
        mDataHandler.handleLiveEvent(event,!isInitialSync && !isRoomInitialSync);
      }
 catch (      Exception e) {
        Log.e(LOG_TAG,"String_Node_Str" + e.getLocalizedMessage());
      }
    }
  }
  if (null != roomSync.accountData) {
    handleAccountDataEvents(roomSync.accountData.events);
  }
  selfMember=getLiveState().getMember(mMyUserId);
  if (null != selfMember) {
    membership=selfMember.membership;
    if (TextUtils.equals(membership,RoomMember.MEMBERSHIP_LEAVE) || TextUtils.equals(membership,RoomMember.MEMBERSHIP_BAN)) {
      if (null != mDataHandler.getStore().getRoom(mRoomId)) {
        mDataHandler.getStore().deleteRoom(mRoomId);
        mDataHandler.onLeaveRoom(mRoomId);
      }
    }
  }
  if (null != mDataHandler.getStore().getRoom(mRoomId)) {
    RoomSummary summary=mDataHandler.getStore().getSummary(mRoomId);
    if (null == summary) {
      Event oldestEvent=mDataHandler.getStore().getOldestEvent(mRoomId);
      if (oldestEvent != null) {
        if (RoomSummary.isSupportedEvent(oldestEvent)) {
          mDataHandler.getStore().storeSummary(oldestEvent.roomId,oldestEvent,getLiveState(),mMyUserId);
          mDataHandler.getStore().commit();
        }
      }
 else       if (null != currentSummary) {
        mDataHandler.getStore().storeSummary(mRoomId,currentSummary.getLatestEvent(),getLiveState(),mMyUserId);
        mDataHandler.getStore().commit();
      }
 else       if ((null != roomSync.state) && (null != roomSync.state.events) && (roomSync.state.events.size() > 0)) {
        ArrayList<Event> events=new ArrayList<Event>(roomSync.state.events);
        Collections.reverse(events);
        for (        Event event : events) {
          event.roomId=mRoomId;
          if (RoomSummary.isSupportedEvent(event)) {
            summary=mDataHandler.getStore().storeSummary(event.roomId,event,getLiveState(),mMyUserId);
            if (Event.EVENT_TYPE_STATE_ROOM_NAME.equals(event.type) || Event.EVENT_TYPE_STATE_ROOM_ALIASES.equals(event.type) || Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(event.type)) {
              if (null != summary) {
                summary.setName(getName(mMyUserId));
              }
            }
            mDataHandler.getStore().commit();
            break;
          }
        }
      }
    }
  }
  if (null != mOnInitialSyncCallback) {
    try {
      mOnInitialSyncCallback.onSuccess(null);
    }
 catch (    Exception e) {
    }
    mOnInitialSyncCallback=null;
  }
  if (null != roomSync.unreadNotifications) {
    int notifCount=0;
    int highlightCount=0;
    if (null != roomSync.unreadNotifications.highlightCount) {
      highlightCount=roomSync.unreadNotifications.highlightCount;
    }
    if (null != roomSync.unreadNotifications.notificationCount) {
      notifCount=roomSync.unreadNotifications.notificationCount;
    }
    boolean isUpdated=(notifCount != getLiveState().mNotificationCount) || (getLiveState().mHighlightCount != highlightCount);
    if (isUpdated) {
      getLiveState().mNotificationCount=notifCount;
      getLiveState().mHighlightCount=highlightCount;
      mDataHandler.getStore().storeLiveStateForRoom(mRoomId);
    }
  }
  mIsV2Syncing=false;
}