private boolean isValidNewLeader(int replica) {
        // The valid new leader should be in either ISR or in ELR when ISR is empty.
        return (targetIsr.contains(replica) || (targetIsr.isEmpty() && targetElr.contains(replica))) &&
            isAcceptableLeader.test(replica);
    }
Assumes that the election type is either Election.ONLINE or Election.UNCLEAN
metadata/src/main/java/org/apache/kafka/controller/PartitionChangeBuilder.java