IllegalStateException when calling BeanValidationBinder.readBean() to popul

In my application I want to display an object’s properties (of type let’s say: “MyObject”) and make them editable using a form.
One of the properties is a Boolean which I want to display and make changeable using a ComboBox like so:

public class MyForm extends FormLayout {
	ComboBox<Boolean> enabled = new ComboBox<>("enabled"); //$NON-NLS-1$
	Binder<Node> binder = new BeanValidationBinder<>(MyObject.class); // a Binder that is aware of bean validation annotations

	public MyForm() {
		enabled.setItems(Boolean.TRUE, Boolean.FALSE);

I then later initialize the object:

MyObject myObj = new MyObject();
... setting object attributes ...

and bind the form with the object using:

	this.binder.readBean(myObj); // to bind the values from the object to the UI fields.

For some reason which I don’t understand this yields the following exception:

java.lang.IllegalStateException: Cannot set a value for a ComboBox without items. Use setItems to populate items into the ComboBox before setting a value.
	at com.vaadin.flow.component.combobox.ComboBox.setValue(
	at java.base/java.util.ArrayList.forEach(

While I understand the error message I can’t see how this can possibly be true.
I am 100% positive (I added tons of denbug statements into my code by now) that I populate that darn ComboBox with values BEFORE calling that readBean(…) method. So how and why can this then claim that the ComboBox is in a wrong state and that I need to call setItems() first?

I even tried with the constructor

	ComboBox<Boolean> enabled = new ComboBox<>("enabled", Boolean.TRUE, Boolean.FALSE); //$NON-NLS-1$

which makes it absolutely sure that there are values but got the very same error.

There must something else be missing or wrong here! Some other assumption or precondition for ComboBox that is not fulfilled here.
Does the form and hence the fields have to be visible before I call that binder or what else could possibly be wrong here and cause this IllegalStateException?

I tried locally and it worked without issues.

What version of Vaadin are you using?

PS. A ComboBox is generally not the best option for selecting from two values, as you don’t need filtering. Consider using a CheckBox or radio button group

Problem solved! As I finally realized the reason for the binder crashing was, that I had set it when the form’s fields had not yet been created.
Of course the fields all existed when calling binder.readBean/writeBean but not yet at the time when I had called binder.bindInstanceFields(this); in the form.

Apparently the bindInstanceField() already does some preparatory activities for the later binding which then later fails if the fields weren’t present at the point in time when the binding was defined.
IMHO this should be changed to lazy evaluation, i.e. that preparation should only take place when readBean/writeBean is actually called the first time.

BTW: thanks for responding and the hint re. CheckBox. I had actually already changed two fields using booleans to CheckBoxes while trying to circumvent the above issue but there was one field left that has three potential values and for that I do need a ComboBox.