private ConsumerGroupMember validateConsumerGroupMember(
        ConsumerGroup group,
        String memberId,
        String instanceId
    ) throws UnknownMemberIdException, FencedInstanceIdException {
        ConsumerGroupMember member;
        if (instanceId == null) {
            member = group.getOrMaybeCreateMember(memberId, false);
        } else {
            member = group.staticMember(instanceId);
            if (member == null) {
                throw new UnknownMemberIdException(
                    String.format("Member with instance id %s is not a member of group %s.", instanceId, group.groupId())
                );
            }
            throwIfInstanceIdIsFenced(member, group.groupId(), memberId, instanceId);
        }
        return member;
    }
Validates that (1) the instance id exists and is mapped to the member id
if the group instance id is provided; and (2) the member id exists in the group.

@param group             The consumer group.
@param memberId          The member id.
@param instanceId        The instance id.

@return The ConsumerGroupMember.
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupMetadataManager.java