-
Bug
-
Resolution: Fixed
-
P4
-
8u5
below are two failing unit tests that demonstrate the misbehaviour. Reason seems to be the wrong order of
properties passed to the binding.
/**
* Bug: BooleanProperty.booleanProperty calls setter
*
* Reason is wrong way round bidi-binding, see below
*/
@Test
public void testBooleanBidiBindingInWrapper() {
List<Object> setterInvokes = new ArrayList<>();
Boolean initialValue = Boolean.FALSE;
ObjectProperty<Boolean> p = new SimpleObjectProperty<Boolean>(initialValue) {
@Override
public void set(Boolean newValue) {
setterInvokes.add(newValue);
super.set(newValue);
}
};
BooleanProperty wrap = BooleanProperty.booleanProperty(p);
assertEquals("wrapper property value must be same", p.getValue(), wrap.getValue());
// accidentally the same (defaults to false)
assertEquals("wrapped property value must be unchanged", initialValue, p.getValue());
assertEquals("wrapped setter must not be called", 0, setterInvokes.size());
}
/**
* Bug: BooleanProperty.booleanProperty changes the value of the wrappee.
*
* The bidi-binding is the wrong way round, that's why the wrappee's
* setter is invoked.
*
* Same for concrete numberProperty (seen in Integer), StringProperty has no
* static wrapper.
*/
@Test
public void testBooleanBidiBindingInWrapperTrueInitial() {
Boolean initialValue = Boolean.TRUE;
ObjectProperty<Boolean> p = new SimpleObjectProperty<Boolean>(initialValue);
assertTrue(p.get());
BooleanProperty wrap = BooleanProperty.booleanProperty(p);
assertEquals("wrapper property value must be same", p.getValue(), wrap.getValue());
assertEquals("wrapped property value must be unchanged", initialValue, p.getValue());
}
properties passed to the binding.
/**
* Bug: BooleanProperty.booleanProperty calls setter
*
* Reason is wrong way round bidi-binding, see below
*/
@Test
public void testBooleanBidiBindingInWrapper() {
List<Object> setterInvokes = new ArrayList<>();
Boolean initialValue = Boolean.FALSE;
ObjectProperty<Boolean> p = new SimpleObjectProperty<Boolean>(initialValue) {
@Override
public void set(Boolean newValue) {
setterInvokes.add(newValue);
super.set(newValue);
}
};
BooleanProperty wrap = BooleanProperty.booleanProperty(p);
assertEquals("wrapper property value must be same", p.getValue(), wrap.getValue());
// accidentally the same (defaults to false)
assertEquals("wrapped property value must be unchanged", initialValue, p.getValue());
assertEquals("wrapped setter must not be called", 0, setterInvokes.size());
}
/**
* Bug: BooleanProperty.booleanProperty changes the value of the wrappee.
*
* The bidi-binding is the wrong way round, that's why the wrappee's
* setter is invoked.
*
* Same for concrete numberProperty (seen in Integer), StringProperty has no
* static wrapper.
*/
@Test
public void testBooleanBidiBindingInWrapperTrueInitial() {
Boolean initialValue = Boolean.TRUE;
ObjectProperty<Boolean> p = new SimpleObjectProperty<Boolean>(initialValue);
assertTrue(p.get());
BooleanProperty wrap = BooleanProperty.booleanProperty(p);
assertEquals("wrapper property value must be same", p.getValue(), wrap.getValue());
assertEquals("wrapped property value must be unchanged", initialValue, p.getValue());
}