vaadin / vaadin/framework

Binder should automatically create intermediate objects if they are null

Open
#9,243 6 comments 2 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.