File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
main/java/javafx/beans/binding
test/java/test/javafx/beans/value Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -180,7 +180,15 @@ public final void invalidate() {
180180 valid = false ;
181181 onInvalidating ();
182182 ExpressionHelper .fireValueChangedEvent (helper );
183- value = null ; // clear cached value to avoid hard reference to stale data
183+
184+ /*
185+ * Cached value should be cleared to avoid a strong reference to stale data,
186+ * but only if this binding didn't become valid after firing the event:
187+ */
188+
189+ if (!valid ) {
190+ value = null ;
191+ }
184192 }
185193 }
186194
Original file line number Diff line number Diff line change @@ -52,6 +52,24 @@ void shouldBeInvalidInitially() {
5252 assertFalse (binding .isValid ());
5353 }
5454
55+ @ Test
56+ void invalidationWhichBecomesValidDuringCallbacksShouldReturnCorrectValue () {
57+ LazyObjectBindingStub <String > binding = new LazyObjectBindingStub <>() {
58+ @ Override
59+ protected String computeValue () {
60+ return "A" ;
61+ }
62+ };
63+
64+ binding .addListener (obs -> {
65+ assertEquals ("A" , binding .get ());
66+ });
67+
68+ binding .invalidate (); // becomes valid again immediately
69+
70+ assertEquals ("A" , binding .get ());
71+ }
72+
5573 @ Nested
5674 class WhenObservedWithInvalidationListener {
5775 private InvalidationListener invalidationListener = obs -> {};
You can’t perform that action at this time.
0 commit comments