private void throwIfConsumerGroupIsFull(
        ConsumerGroup group,
        String memberId
    ) throws GroupMaxSizeReachedException {
        // If the consumer group has reached its maximum capacity, the member is rejected if it is not
        // already a member of the consumer group.
        if (group.numMembers() >= consumerGroupMaxSize && (memberId.isEmpty() || !group.hasMember(memberId))) {
            throw new GroupMaxSizeReachedException("The consumer group has reached its maximum capacity of "
                + consumerGroupMaxSize + " members.");
        }
    }
Checks whether the consumer group can accept a new member or not based on the
max group size defined.

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

@throws GroupMaxSizeReachedException if the maximum capacity has been reached.
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupMetadataManager.java