Program: 32176
Project: 32176
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,Room.EventDirection direction){
  if (event.stateKey == null) {
    return false;
  }
  JsonObject contentToConsider=(direction == Room.EventDirection.FORWARDS) ? event.getContentAsJsonObject() : event.getPrevContentAsJsonObject();
  try {
    if (Event.EVENT_TYPE_STATE_ROOM_NAME.equals(event.type)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      name=(roomState == null) ? null : roomState.name;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_TOPIC.equals(event.type)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      topic=(roomState == null) ? null : roomState.topic;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_CREATE.equals(event.type)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      creator=(roomState == null) ? null : roomState.creator;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_JOIN_RULES.equals(event.type)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      join_rule=(roomState == null) ? null : roomState.join_rule;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_ALIASES.equals(event.type)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      aliases=(roomState == null) ? null : roomState.aliases;
    }
 else     if (Event.EVENT_TYPE_STATE_CANONICAL_ALIAS.equals(event.type)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      alias=(roomState == null) ? null : roomState.alias;
    }
 else     if (Event.EVENT_TYPE_STATE_HISTORY_VISIBILITY.equals(event.type)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      history_visibility=(roomState == null) ? null : roomState.history_visibility;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_AVATAR.equals(event.type)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      url=(roomState == null) ? null : roomState.url;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(event.type)) {
      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());
        RoomMember currentMember=getMember(userId);
        if (member.equals(currentMember)) {
          return false;
        }
        if ((direction == Room.EventDirection.FORWARDS)) {
          if (null != currentMember) {
            if (member.membership.equals(RoomMember.MEMBERSHIP_LEAVE) || member.membership.equals(RoomMember.MEMBERSHIP_BAN)) {
              if (null == member.avatarUrl) {
                member.avatarUrl=currentMember.avatarUrl;
              }
            }
          }
          updateUser(member);
        }
        setMember(userId,member);
      }
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_POWER_LEVELS.equals(event.type)) {
      powerLevels=JsonUtils.toPowerLevels(contentToConsider);
    }
  }
 catch (  Exception e) {
  }
  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,Room.EventDirection direction){
  if (event.stateKey == null) {
    return false;
  }
  JsonObject contentToConsider=(direction == Room.EventDirection.FORWARDS) ? event.getContentAsJsonObject() : event.getPrevContentAsJsonObject();
  try {
    if (Event.EVENT_TYPE_STATE_ROOM_NAME.equals(event.type)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      name=(roomState == null) ? null : roomState.name;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_TOPIC.equals(event.type)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      topic=(roomState == null) ? null : roomState.topic;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_CREATE.equals(event.type)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      creator=(roomState == null) ? null : roomState.creator;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_JOIN_RULES.equals(event.type)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      join_rule=(roomState == null) ? null : roomState.join_rule;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_ALIASES.equals(event.type)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      aliases=(roomState == null) ? null : roomState.aliases;
    }
 else     if (Event.EVENT_TYPE_STATE_CANONICAL_ALIAS.equals(event.type)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      alias=(roomState == null) ? null : roomState.alias;
    }
 else     if (Event.EVENT_TYPE_STATE_HISTORY_VISIBILITY.equals(event.type)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      history_visibility=(roomState == null) ? null : roomState.history_visibility;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_AVATAR.equals(event.type)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      url=(roomState == null) ? null : roomState.url;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(event.type)) {
      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());
        RoomMember currentMember=getMember(userId);
        if (member.equals(currentMember)) {
          return false;
        }
        if ((direction == Room.EventDirection.FORWARDS)) {
          if (null != currentMember) {
            if (member.membership.equals(RoomMember.MEMBERSHIP_LEAVE) || member.membership.equals(RoomMember.MEMBERSHIP_BAN)) {
              if (null == member.avatarUrl) {
                member.avatarUrl=currentMember.avatarUrl;
              }
            }
          }
          if (null != mDataHandler) {
            ((MXDataHandler)mDataHandler).getStore().updateUserWithRoomMemberEvent(member);
          }
        }
        setMember(userId,member);
      }
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_POWER_LEVELS.equals(event.type)) {
      powerLevels=JsonUtils.toPowerLevels(contentToConsider);
    }
  }
 catch (  Exception e) {
  }
  return true;
}