Program: 32008
Project: 32008
Buggy source:
/** 
 * Apply the given event (relevant for state changes) to our state.
 * @param event     the event
 * @param direction how the event should affect the state: Forwards for applying, backwards for un-applying (applying the previous state)
 * @return true if the event is managed
 */
public boolean applyState(Event event,EventTimeline.Direction direction){
  if (event.stateKey == null) {
    return false;
  }
  JsonObject contentToConsider=(direction == EventTimeline.Direction.FORWARDS) ? event.getContentAsJsonObject() : event.getPrevContentAsJsonObject();
  String eventType=event.getType();
  try {
    if (Event.EVENT_TYPE_STATE_ROOM_NAME.equals(eventType)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      name=(roomState == null) ? null : roomState.name;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_TOPIC.equals(eventType)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      topic=(roomState == null) ? null : roomState.topic;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_CREATE.equals(eventType)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      creator=(roomState == null) ? null : roomState.creator;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_JOIN_RULES.equals(eventType)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      join_rule=(roomState == null) ? null : roomState.join_rule;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_GUEST_ACCESS.equals(eventType)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      guest_access=(roomState == null) ? null : roomState.guest_access;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_ALIASES.equals(eventType)) {
      if (!TextUtils.isEmpty(event.stateKey)) {
        RoomState roomState=JsonUtils.toRoomState(contentToConsider);
        aliases=(null == roomState) ? null : roomState.aliases;
        if (null != aliases) {
          mAliasesByDomain.put(event.stateKey,aliases);
          mRoomAliases.put(event.stateKey,event);
        }
 else {
          mAliasesByDomain.put(event.stateKey,new ArrayList<String>());
        }
      }
    }
 else     if (Event.EVENT_TYPE_MESSAGE_ENCRYPTION.equals(eventType)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      algorithm=(roomState == null) ? null : roomState.algorithm;
    }
 else     if (Event.EVENT_TYPE_STATE_CANONICAL_ALIAS.equals(eventType)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      alias=(roomState == null) ? null : roomState.alias;
    }
 else     if (Event.EVENT_TYPE_STATE_HISTORY_VISIBILITY.equals(eventType)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      history_visibility=(roomState == null) ? null : roomState.history_visibility;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_AVATAR.equals(eventType)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      url=(roomState == null) ? null : roomState.url;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(eventType)) {
      RoomMember member=JsonUtils.toRoomMember(contentToConsider);
      String userId=event.stateKey;
      if (member == null) {
        if (null == getMember(userId)) {
          return false;
        }
        removeMember(userId);
      }
 else {
        member.setUserId(userId);
        member.setOriginServerTs(event.getOriginServerTs());
        member.setInviterId(event.getSender());
        ((MXDataHandler)mDataHandler).getStore().storeRoomStateEvent(roomId,event);
        RoomMember currentMember=getMember(userId);
        if (member.equals(currentMember)) {
          return false;
        }
        if (null != currentMember) {
          if (member.membership.equals(RoomMember.MEMBERSHIP_LEAVE) || member.membership.equals(RoomMember.MEMBERSHIP_BAN)) {
            if (null == member.getAvatarUrl()) {
              member.setAvatarUrl(currentMember.getAvatarUrl());
            }
            if (null == member.displayname) {
              member.displayname=currentMember.displayname;
            }
            if (null != mMemberDisplayNameByUserId) {
              mMemberDisplayNameByUserId.remove(userId);
            }
          }
        }
        if ((direction == EventTimeline.Direction.FORWARDS)) {
          if (null != mDataHandler) {
            ((MXDataHandler)mDataHandler).getStore(roomId).updateUserWithRoomMemberEvent(member);
          }
        }
        if (!TextUtils.isEmpty(member.getThirdPartyInviteToken())) {
          mMembersWithThirdPartyInviteTokenCache.put(member.getThirdPartyInviteToken(),member);
        }
        setMember(userId,member);
      }
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_POWER_LEVELS.equals(eventType)) {
      powerLevels=JsonUtils.toPowerLevels(contentToConsider);
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_THIRD_PARTY_INVITE.equals(event.getType())) {
      RoomThirdPartyInvite thirdPartyInvite=JsonUtils.toRoomThirdPartyInvite(contentToConsider);
      thirdPartyInvite.token=event.stateKey;
      ((MXDataHandler)mDataHandler).getStore().storeRoomStateEvent(roomId,event);
      if (!TextUtils.isEmpty(thirdPartyInvite.token)) {
        mThirdPartyInvites.put(thirdPartyInvite.token,thirdPartyInvite);
      }
    }
    mStateEvents.put(eventType,event);
  }
 catch (  Exception e) {
    Log.e(LOG_TAG,"String_Node_Str" + e.getLocalizedMessage());
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Apply the given event (relevant for state changes) to our state.
 * @param event     the event
 * @param direction how the event should affect the state: Forwards for applying, backwards for un-applying (applying the previous state)
 * @return true if the event is managed
 */
public boolean applyState(Event event,EventTimeline.Direction direction){
  if (event.stateKey == null) {
    return false;
  }
  JsonObject contentToConsider=(direction == EventTimeline.Direction.FORWARDS) ? event.getContentAsJsonObject() : event.getPrevContentAsJsonObject();
  String eventType=event.getType();
  try {
    if (Event.EVENT_TYPE_STATE_ROOM_NAME.equals(eventType)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      name=(roomState == null) ? null : roomState.name;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_TOPIC.equals(eventType)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      topic=(roomState == null) ? null : roomState.topic;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_CREATE.equals(eventType)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      creator=(roomState == null) ? null : roomState.creator;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_JOIN_RULES.equals(eventType)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      join_rule=(roomState == null) ? null : roomState.join_rule;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_GUEST_ACCESS.equals(eventType)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      guest_access=(roomState == null) ? null : roomState.guest_access;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_ALIASES.equals(eventType)) {
      if (!TextUtils.isEmpty(event.stateKey)) {
        RoomState roomState=JsonUtils.toRoomState(contentToConsider);
        aliases=(null == roomState) ? null : roomState.aliases;
        if (null != aliases) {
          mAliasesByDomain.put(event.stateKey,aliases);
          mRoomAliases.put(event.stateKey,event);
        }
 else {
          mAliasesByDomain.put(event.stateKey,new ArrayList<String>());
        }
      }
    }
 else     if (Event.EVENT_TYPE_MESSAGE_ENCRYPTION.equals(eventType)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      algorithm=(roomState == null) ? null : roomState.algorithm;
    }
 else     if (Event.EVENT_TYPE_STATE_CANONICAL_ALIAS.equals(eventType)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      alias=(roomState == null) ? null : roomState.alias;
    }
 else     if (Event.EVENT_TYPE_STATE_HISTORY_VISIBILITY.equals(eventType)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      history_visibility=(roomState == null) ? null : roomState.history_visibility;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_AVATAR.equals(eventType)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      url=(roomState == null) ? null : roomState.url;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(eventType)) {
      RoomMember member=JsonUtils.toRoomMember(contentToConsider);
      String userId=event.stateKey;
      if (member == null) {
        if (null == getMember(userId)) {
          return false;
        }
        removeMember(userId);
      }
 else {
        member.setUserId(userId);
        member.setOriginServerTs(event.getOriginServerTs());
        member.setInviterId(event.getSender());
        MXDataHandler dataHandler=(MXDataHandler)mDataHandler;
        if ((null != dataHandler) && (null != dataHandler.getStore())) {
          dataHandler.getStore().storeRoomStateEvent(roomId,event);
        }
        RoomMember currentMember=getMember(userId);
        if (member.equals(currentMember)) {
          return false;
        }
        if (null != currentMember) {
          if (member.membership.equals(RoomMember.MEMBERSHIP_LEAVE) || member.membership.equals(RoomMember.MEMBERSHIP_BAN)) {
            if (null == member.getAvatarUrl()) {
              member.setAvatarUrl(currentMember.getAvatarUrl());
            }
            if (null == member.displayname) {
              member.displayname=currentMember.displayname;
            }
            if (null != mMemberDisplayNameByUserId) {
              mMemberDisplayNameByUserId.remove(userId);
            }
          }
        }
        if ((direction == EventTimeline.Direction.FORWARDS)) {
          if (null != mDataHandler) {
            ((MXDataHandler)mDataHandler).getStore(roomId).updateUserWithRoomMemberEvent(member);
          }
        }
        if (!TextUtils.isEmpty(member.getThirdPartyInviteToken())) {
          mMembersWithThirdPartyInviteTokenCache.put(member.getThirdPartyInviteToken(),member);
        }
        setMember(userId,member);
      }
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_POWER_LEVELS.equals(eventType)) {
      powerLevels=JsonUtils.toPowerLevels(contentToConsider);
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_THIRD_PARTY_INVITE.equals(event.getType())) {
      RoomThirdPartyInvite thirdPartyInvite=JsonUtils.toRoomThirdPartyInvite(contentToConsider);
      thirdPartyInvite.token=event.stateKey;
      ((MXDataHandler)mDataHandler).getStore().storeRoomStateEvent(roomId,event);
      if (!TextUtils.isEmpty(thirdPartyInvite.token)) {
        mThirdPartyInvites.put(thirdPartyInvite.token,thirdPartyInvite);
      }
    }
    mStateEvents.put(eventType,event);
  }
 catch (  Exception e) {
    Log.e(LOG_TAG,"String_Node_Str" + e.getLocalizedMessage());
  }
  return true;
}