8 – Form Set Error breaks validation – Allowed memory size of xxx bytes exhausted

I’m creating a simple form :

class UserRegisterForm extends FormBase {

    /**
    * {@inheritdoc}
    */
    public function getFormId() {
    return 'user_register_form';
    }

    /**
    * {@inheritdoc}
    */
    public function buildForm(array $form, FormStateInterface $form_state) {
        ...

        return $form;
    }

    /**
    * {@inheritdoc}
    */
    public function validateForm(array &$form, FormStateInterface $form_state) {
        $form_state->setError($form, $this->t('The password must contain at least 12 characters, including 1 lowercase, 1 uppercase and 1 special character.'));
    }

    /**
    * {@inheritdoc}
    */
    public function submitForm(array &$form, FormStateInterface $form_state) {}

}

But when I use the setError() or setErrorByName() methods, I get a “Allowed memory size of XXX bytes exhausted” error when I submit the form.

The logs gives me thousands of 404 Page Not Found errors on my form page, like it was giving me an infinite loop.

Any ideas ?