private void assertValidTransition(ClassicGroupState targetState) {
        if (!targetState.validPreviousStates().contains(state)) {
            throw new IllegalStateException("Group " + groupId + " should be in one of " +
                targetState.validPreviousStates() + " states before moving to " + targetState +
                " state. Instead it is in " + state + " state.");
        }
    }
Checks whether the transition to the target state is valid.

@param targetState the target state to transition to.
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/classic/ClassicGroup.java