Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8089579

'then()' is executed while 'when()' produces 'false'

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u20
    • javafx
    • JDK 8u20, Win 7 Pro SP1, 64 Bit

      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.

            nlisker Nir Lisker
            mkarg Markus Karg
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Imported: