Null Pointer Exception in ItemPropertyChangeListener


I have set a ItemPropertyChangeListener for a datasource’s related Entity attribute on a Edit screen (PickerField). It is working fine except for the scenario where the user selected the same related Entity from the related entity’s lookup screen. The problem is i got “nullpointerexception” in the listener code after returning from the lookup screen.

Seem like the listener is being triggered twice under this scenario - first time it changed the related entity attribute in the datasource to null (which causes the “nullpointerexception”) and then a second time it changed back to the original value. I couldn’t figure it out to solve the problem. Would much appreciate if anyone can help me out . Thanks in advance.

Attaching the screen controller codes as below:

public class ClientEdit extends AbstractEditor<Client> {

    private Datasource<Client> clientDs;
    private Datasource<Party> partyDs;

    private LookupPickerField partyField;

    private TextField clientNoField;

    public void init(Map<String, Object> params) {

        clientDs.addItemPropertyChangeListener(e -> {
            if ("party".equals(e.getProperty())) {
                if (clientDs.getItem().getParty().getPartyType() == PartyType.Individual) {


For now PickerField LookupAction calls setValue() method twice (with null value and with the selected) if the new item has the same id as current to ensure that previous item will be replaced with the new.

It is a known API issue and we will try to change it may be in the next major release of the platform, but now you have to check for null e.getValue() and entity attribute that is bound to a PickerField. In your case it is clientDs.getItem().getParty().

Thanks for the explanation Yuriy. Look forward to the improvement in next release.

For now, i check for null first to avoid the runtime error.

Best regards,
David See

:ticket: See the following issue in our bug tracker: