ConsumerGroup getOrMaybeCreateConsumerGroup(
        String groupId,
        boolean createIfNotExists,
        List<CoordinatorRecord> records
    ) throws GroupIdNotFoundException {
        Group group = groups.get(groupId);

        if (group == null && !createIfNotExists) {
            throw new GroupIdNotFoundException(String.format("Consumer group %s not found.", groupId));
        }

        if (group == null || (createIfNotExists && maybeDeleteEmptyClassicGroup(group, records))) {
            return new ConsumerGroup(snapshotRegistry, groupId, metrics);
        } else {
            if (group.type() == CONSUMER) {
                return (ConsumerGroup) group;
            } else if (createIfNotExists && validateOnlineUpgrade((ClassicGroup) group)) {
                return convertToConsumerGroup((ClassicGroup) group, records);
            } else {
                throw new GroupIdNotFoundException(String.format("Group %s is not a consumer group.",
                    groupId));
            }
        }
    }
Gets or maybe creates a consumer group without updating the groups map.
The group will be materialized during the replay.

@param groupId           The group id.
@param createIfNotExists A boolean indicating whether the group should be
                         created if it does not exist or is an empty classic group.
@param records           The record list to which the group tombstones are written
                         if the group is empty and is a classic group.

@return A ConsumerGroup.
@throws GroupIdNotFoundException if the group does not exist and createIfNotExists is false or
                                 if the group is not a consumer group.

Package private for testing.
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupMetadataManager.java