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

bindBidirectional behaves differently when done in reverse order with one of its properties bound

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 8
    • javafx
    • JavaFX 8 b109

      When one of the properties is bound with bind(), and you then apply a bindBidirectional between that property and another, the direction in which you do this (a.bindBidirectional(b) or b.bindBidirectional(a)) matters. One will throw an exception -- the other will not.

      package hs.mediasystem.screens.collection.detail;

      import static org.junit.Assert.assertEquals;
      import hs.mediasystem.test.JavaFXRunningRule;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.beans.property.StringProperty;

      import org.junit.Rule;
      import org.junit.Test;

      public class BoundBidirectionalPropertyTest {

        @Rule
        public final JavaFXRunningRule jfxRunningRule = new JavaFXRunningRule();

        @Test(expected = RuntimeException.class)
        public void shouldThrowException() {
          StringProperty a = new SimpleStringProperty("a");
          StringProperty b = new SimpleStringProperty("b");
          StringProperty c = new SimpleStringProperty("c");

          b.bind(a);
          b.bindBidirectional(c); // Throws exception "A bound value cannot be set"

          assertEquals("a", a.get());
          assertEquals("a", b.get());
          assertEquals("a", c.get());
        }

        @Test(expected = RuntimeException.class)
        public void shouldAlsoThrowException() {
          StringProperty a = new SimpleStringProperty("a");
          StringProperty b = new SimpleStringProperty("b");
          StringProperty c = new SimpleStringProperty("c");

          b.bind(a);
          c.bindBidirectional(b); // Does not throw exception...

          assertEquals("a", a.get());
          assertEquals("a", b.get());
          assertEquals("a", c.get());
        }
      }

            msladecek Martin Sládeček
            jhendrikx John Hendrikx
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: