Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binder.removeBinding issue #5384

Closed
nbabb opened this issue Apr 1, 2019 · 3 comments · Fixed by #6827
Closed

Binder.removeBinding issue #5384

nbabb opened this issue Apr 1, 2019 · 3 comments · Fixed by #6827
Assignees
Labels

Comments

@nbabb
Copy link

nbabb commented Apr 1, 2019

In Vaadin flow 1.0.5, I have several fields bound to a Binder instance. When I remove a binding (where there are still other bound properties) it is calling unbind. It seems like it should only call unbind when the count of bound properties is zero? Here is the code.

public void removeBinding(String propertyName) {
    Objects.requireNonNull(propertyName, "Property name may not be null");
    Optional.ofNullable(boundProperties.get(propertyName))
            .ifPresent(Binding::unbind);
}

I end up receiving errors after I remove the binding

java.lang.NullPointerException: This Binding is no longer attached to a Binder
at java.base/java.util.Objects.requireNonNull(Objects.java:246) ~[na:na]
at com.vaadin.flow.data.binder.Binder$BindingImpl.validate(Binder.java:1027) ~[flow-data-1.0.5.jar:na]

from my other bound fields that are still using the binding.

Perhaps I'm misunderstanding how this should work? See vaadin/framework#11280 for reference

@ZheSun88
Copy link
Contributor

ZheSun88 commented Apr 2, 2019

The first thing i would suggest you is updating your flow version to the latest ones, ( if you are using flow separately, the version number is 1.0.10). could you try with that one?

@atistrcsn
Copy link

atistrcsn commented Jun 3, 2019

vaadin/framework#11280

The WorkaroundBinder mentioned in @lulnope's answer is actually a good temporary solution.
It should be included in a bugfix. I don't have experience how to prepare one.

@ZheSun88 This WorkaroundBinder was worked for me, I have flow version 1.4.4.

@denis-anisimov
Copy link
Contributor

Looks like this is a bug in Binder.

Refer to vaadin/framework#11280 (comment) to fix it:

The issue is located in Binder class in its protected void removeBindingInternal(Binding<T, ?> binding) method. Currently it looks as follows:

protected void removeBindingInternal(Binding<BEAN, ?> binding) {
        if (bindings.remove(binding)) {
            boundProperties.entrySet()
                    .removeIf(entry -> entry.getValue().equals(binding));
        }
    }

it's missing: changedBindings.remove(binding)
which should resolve this error:
java.lang.NullPointerException: This Binding is no longer attached to a Binder

@denis-anisimov denis-anisimov self-assigned this Nov 2, 2019
ujoni pushed a commit that referenced this issue Nov 7, 2019
ujoni pushed a commit that referenced this issue Nov 7, 2019
ujoni pushed a commit that referenced this issue Nov 7, 2019
ujoni pushed a commit that referenced this issue Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants