In case one wants to bind to list indices, but it might happen that list indices are past end of the list, the programmer typically uses "when-then-otherwise" bindings to be safe of "IndexOutOfBound" warnings. Unfortunately this is not working, as apparently "then()" is executed even if "when()" produces false.
To proof this, I did the following...
w = Bindings.size(myListProperty);
t = Bindings.valueAt(myListProperty, Integer.MAX_VALUE);
myintegerProperty.bind(Bindings.when(w).then(t).otherwise(null))
...and what happens at runtime is the it prints a warning due to IndexOutOfBound!
This is rather strange, because the typical programmer would expect that a "when" indicates that the "then" expression is ONLY resolved in case "when" produces "true" -- but apprently it is ALWAYS resolved and then the result is thrown away.
Not is rather ugly. "when" producing "false" should prevent "then" from being resolved, since there is no other clever way (besides coding a new expression type) to deal with situations like this.
To proof this, I did the following...
w = Bindings.size(myListProperty);
t = Bindings.valueAt(myListProperty, Integer.MAX_VALUE);
myintegerProperty.bind(Bindings.when(w).then(t).otherwise(null))
...and what happens at runtime is the it prints a warning due to IndexOutOfBound!
This is rather strange, because the typical programmer would expect that a "when" indicates that the "then" expression is ONLY resolved in case "when" produces "true" -- but apprently it is ALWAYS resolved and then the result is thrown away.
Not is rather ugly. "when" producing "false" should prevent "then" from being resolved, since there is no other clever way (besides coding a new expression type) to deal with situations like this.
- is blocked by
-
JDK-8208750 Attaching an InvalidationListener causes evaluation
- Open
- relates to
-
JDK-8199560 Dynamic evaluation for binding.When
- In Progress
-
JDK-8199514 Refactor binding.When
- In Progress