Details
-
Bug
-
Resolution: Fixed
-
P2
-
jfx19
Backports
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8290395 | jfx20 | John Hendrikx | P2 | Resolved | Fixed | b01 |
Description
I just discovered a bug that was introduced as part of the fluent bindings PR. It affects all ObjectBinding's.
Below program will print "null" for binding.getValue(), which is incorrect (it should be false).
SimpleObjectProperty<Boolean> condition = new SimpleObjectProperty<>(true);
ObservableValue<String> binding = condition.map(Object::toString);
binding.addListener(o -> { binding.getValue(); });
condition.set(false);
System.out.println(">>> binding: " + binding.getValue());
This is caused by the clearing of the cached value in ObjectBinding when a binding is being invalidated. This clearing however did not take into account that the binding might become valid again while it is informing its listeners.
This is fixed by checking if the binding is still invalid after calling listeners before clearing the value:
@Override
public final void invalidate() {
if (valid) {
valid = false;
onInvalidating();
ExpressionHelper.fireValueChangedEvent(helper);
if (!valid) { // if still invalid after calling listeners...
value = null; // clear cached value to avoid hard reference to stale data
}
}
}
I think this must be fixed in jfx 19 or the fluent bindings PR must be reverted.
I will open a PR in a moment which solves the issue.
Below program will print "null" for binding.getValue(), which is incorrect (it should be false).
SimpleObjectProperty<Boolean> condition = new SimpleObjectProperty<>(true);
ObservableValue<String> binding = condition.map(Object::toString);
binding.addListener(o -> { binding.getValue(); });
condition.set(false);
System.out.println(">>> binding: " + binding.getValue());
This is caused by the clearing of the cached value in ObjectBinding when a binding is being invalidated. This clearing however did not take into account that the binding might become valid again while it is informing its listeners.
This is fixed by checking if the binding is still invalid after calling listeners before clearing the value:
@Override
public final void invalidate() {
if (valid) {
valid = false;
onInvalidating();
ExpressionHelper.fireValueChangedEvent(helper);
if (!valid) { // if still invalid after calling listeners...
value = null; // clear cached value to avoid hard reference to stale data
}
}
}
I think this must be fixed in jfx 19 or the fluent bindings PR must be reverted.
I will open a PR in a moment which solves the issue.
Attachments
Issue Links
- backported by
-
JDK-8290395 Binding value left null when immediately revalidated in invalidation listener
- Resolved
- duplicates
-
JDK-8291552 Select binding not updated correctly in JavaFX 19-ea+9
- Closed
- relates to
-
JDK-8274771 Map, FlatMap and OrElse fluent bindings for ObservableValue
- Resolved