private void validateMemberEpoch(
        int receivedMemberEpoch,
        int expectedMemberEpoch,
        boolean useClassicProtocol
    ) throws StaleMemberEpochException, IllegalGenerationException {
        if (receivedMemberEpoch != expectedMemberEpoch) {
            if (useClassicProtocol) {
                throw new IllegalGenerationException(String.format("The received generation id %d does not match " +
                    "the expected member epoch %d.", receivedMemberEpoch, expectedMemberEpoch));
            } else {
                throw new StaleMemberEpochException(String.format("The received member epoch %d does not match "
                    + "the expected member epoch %d.", receivedMemberEpoch, expectedMemberEpoch));
            }
        }
    }
Throws an exception if the received member epoch does not match the expected member epoch.

@param receivedMemberEpoch   The received member epoch or generation id.
@param expectedMemberEpoch   The expected member epoch.
@param useClassicProtocol    The boolean indicating whether the checked member uses the classic protocol.
@throws StaleMemberEpochException    if the member with unmatched member epoch uses the consumer protocol.
@throws IllegalGenerationException   if the member with unmatched generation id uses the classic protocol.
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/modern/consumer/ConsumerGroup.java