BeanPathAdapter treats empty strings differently than non-empty strings when using bindBidirectional.
ryanjaeb opened this issue · 1 comments
ryanjaeb commented
When initial binding is done using BeanPathAdapter, empty strings get treated differently than non-empty strings. The example below illustrates what I mean. The initial binding appears to happen in one direction for the first case, and the opposite direction for the second.
If emptyStringProperty is left without an initial value, it will default to null and, after binding is done, the emptyString value in the bean will be 'null'. Based on the following comment in the source, I assume this isn't the intended behavior.
// because of the inverse relationship of the bidirectional
// bind the initial value needs to be captured and reset as
// a dirty value or the bind operation will overwrite the
// initial value with the value of the passed property
I tested with the following versions:
2.2-r5
2.2-r6-20130906.083338-9
8.0-8.0-r1-20130906.112928-11
public class BPAEmptyVsNormal {
public static void main(String[] args) {
Bean bean = new Bean();
StringProperty emptyStringProperty = new SimpleStringProperty("initial");
StringProperty normalStringProperty = new SimpleStringProperty("initial");
BeanPathAdapter<Bean> adapter = new BeanPathAdapter<>(bean);
adapter.bindBidirectional("emptyString", emptyStringProperty);
adapter.bindBidirectional("normalString", normalStringProperty);
System.out.println(bean.getEmptyString()); // prints 'initial'
System.out.println(bean.getNormalString()); // prints 'normal'
}
public static class Bean {
private String emptyString = "";
private String normalString = "normal";
public String getEmptyString() {
return emptyString;
}
public void setEmptyString(String emptyString) {
this.emptyString = emptyString;
}
public String getNormalString() {
return normalString;
}
public void setNormalString(String normalString) {
this.normalString = normalString;
}
}
}
tbee commented
Closed because of inactivity