Program: 32109
Project: 32109
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();
  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_GUEST_ACCESS.equals(event.type)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      guest_access=(roomState == null) ? null : roomState.guest_access;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_ALIASES.equals(event.type)) {
      if (!TextUtils.isEmpty(event.stateKey)) {
        RoomState roomState=JsonUtils.toRoomState(contentToConsider);
        mAliasesByDomain.put(event.stateKey,(null == roomState) ? 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 == EventTimeline.Direction.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);
          }
        }
        if (!TextUtils.isEmpty(member.getThirdPartyInviteToken())) {
          mMembersWithThirdPartyInviteTokenCache.put(member.getThirdPartyInviteToken(),member);
        }
        setMember(userId,member);
      }
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_POWER_LEVELS.equals(event.type)) {
      powerLevels=JsonUtils.toPowerLevels(contentToConsider);
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_THIRD_PARTY_INVITE.equals(event.type)) {
      RoomThirdPartyInvite thirdPartyInvite=JsonUtils.toRoomThirdPartyInvite(contentToConsider);
      thirdPartyInvite.token=event.stateKey;
      if (!TextUtils.isEmpty(thirdPartyInvite.token)) {
        mThirdPartyInvites.put(thirdPartyInvite.token,thirdPartyInvite);
      }
    }
  }
 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();
  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_GUEST_ACCESS.equals(event.type)) {
      RoomState roomState=JsonUtils.toRoomState(contentToConsider);
      guest_access=(roomState == null) ? null : roomState.guest_access;
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_ALIASES.equals(event.type)) {
      if (!TextUtils.isEmpty(event.stateKey)) {
        RoomState roomState=JsonUtils.toRoomState(contentToConsider);
        aliases=(null == roomState) ? null : roomState.aliases;
        if (null != aliases) {
          mAliasesByDomain.put(event.stateKey,aliases);
        }
 else {
          mAliasesByDomain.put(event.stateKey,new ArrayList<String>());
        }
      }
    }
 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 == EventTimeline.Direction.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);
          }
        }
        if (!TextUtils.isEmpty(member.getThirdPartyInviteToken())) {
          mMembersWithThirdPartyInviteTokenCache.put(member.getThirdPartyInviteToken(),member);
        }
        setMember(userId,member);
      }
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_POWER_LEVELS.equals(event.type)) {
      powerLevels=JsonUtils.toPowerLevels(contentToConsider);
    }
 else     if (Event.EVENT_TYPE_STATE_ROOM_THIRD_PARTY_INVITE.equals(event.type)) {
      RoomThirdPartyInvite thirdPartyInvite=JsonUtils.toRoomThirdPartyInvite(contentToConsider);
      thirdPartyInvite.token=event.stateKey;
      if (!TextUtils.isEmpty(thirdPartyInvite.token)) {
        mThirdPartyInvites.put(thirdPartyInvite.token,thirdPartyInvite);
      }
    }
  }
 catch (  Exception e) {
    Log.e(LOG_TAG,"String_Node_Str" + e.getLocalizedMessage());
  }
  return true;
}