Add missing if from previous commit to v25-v27

(cherry picked from commit a81960ee3b867e91a4bcae906976a58d6de66d71)