ClassicGroup getOrMaybeCreateClassicGroup(
        String groupId,
        boolean createIfNotExists
    ) throws UnknownMemberIdException, GroupIdNotFoundException {
        Group group = groups.get(groupId);

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

        if (group == null) {
            ClassicGroup classicGroup = new ClassicGroup(logContext, groupId, ClassicGroupState.EMPTY, time, metrics);
            groups.put(groupId, classicGroup);
            metrics.onClassicGroupStateTransition(null, classicGroup.currentState());
            return classicGroup;
        } else {
            if (group.type() == CLASSIC) {
                return (ClassicGroup) group;
            } else {
                // We don't support upgrading/downgrading between protocols at the moment so
                // we throw an exception if a group exists with the wrong type.
                throw new GroupIdNotFoundException(String.format("Group %s is not a classic group.",
                    groupId));
            }
        }
    }
Gets or maybe creates a classic group.

@param groupId           The group id.
@param createIfNotExists A boolean indicating whether the group should be
                         created if it does not exist.

@return A ClassicGroup.
@throws UnknownMemberIdException if the group does not exist and createIfNotExists is false.
@throws GroupIdNotFoundException if the group is not a classic group.

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