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

@param group     The share 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