Binder should automatically create intermediate objects if they are null
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- Java
- Stars
- 1.8k
- Forks
- 717
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 3
Description
public class Order {
@OneToOne
private Customer customer;
}
public class Customer {
@NotNull
@NotEmpty
private String firstName;
}
protected TextField firstName = new TextField();
BeanValidationBinder<Order> binder = new BeanValidationBinder<>(Order.class);
binder.bind(firstName, "customer.firstName");
binder.setBean(new Order());
causes
java.lang.NullPointerException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.vaadin.data.BeanPropertySet.invokeWrapExceptions(BeanPropertySet.java:357)
at com.vaadin.data.BeanPropertySet.access$1(BeanPropertySet.java:354)
at com.vaadin.data.BeanPropertySet$NestedBeanPropertyDefinition.lambda$0(BeanPropertySet.java:219)
at com.vaadin.data.Binder$BindingImpl.convertDataToFieldType(Binder.java:899)
at com.vaadin.data.Binder$BindingImpl.initFieldValue(Binder.java:890)
at com.vaadin.data.Binder$BindingImpl.access$0(Binder.java:885)
at com.vaadin.data.Binder.lambda$1(Binder.java:1341)
at java.lang.Iterable.forEach(Iterable.java:75)
at com.vaadin.data.Binder.setBean(Binder.java:1341)
because the Customer bean is not created before trying to run its getter.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the nested-property handling in com.vaadin.data.BeanPropertySet, especially NestedBeanPropertyDefinition, and the binding initialization path in com.vaadin.data.Binder. Reproduce the NullPointerException with the Order, Customer, BeanValidationBinder, and firstName example; done means binding customer.firstName on a new Order no longer fails because the intermediate Customer is null.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100