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

BooleanProperty.booleanProperty(ObjectProperty<Boolean>) changes value of source property

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8u20
    • 8u5
    • javafx

      below are two failing unit tests that demonstrate the misbehaviour. Reason seems to be the wrong order of
      properties passed to the binding.


          /**
           * Bug: BooleanProperty.booleanProperty calls setter
           *
           * Reason is wrong way round bidi-binding, see below
           */
          @Test
          public void testBooleanBidiBindingInWrapper() {
              List<Object> setterInvokes = new ArrayList<>();
              Boolean initialValue = Boolean.FALSE;
              ObjectProperty<Boolean> p = new SimpleObjectProperty<Boolean>(initialValue) {
                  
                  @Override
                  public void set(Boolean newValue) {
                      setterInvokes.add(newValue);
                      super.set(newValue);
                  }
                  
              };
              BooleanProperty wrap = BooleanProperty.booleanProperty(p);
              assertEquals("wrapper property value must be same", p.getValue(), wrap.getValue());
              // accidentally the same (defaults to false)
              assertEquals("wrapped property value must be unchanged", initialValue, p.getValue());
              assertEquals("wrapped setter must not be called", 0, setterInvokes.size());
          }
          
          /**
           * Bug: BooleanProperty.booleanProperty changes the value of the wrappee.
           *
           * The bidi-binding is the wrong way round, that's why the wrappee's
           * setter is invoked.
           *
           * Same for concrete numberProperty (seen in Integer), StringProperty has no
           * static wrapper.
           */
          @Test
          public void testBooleanBidiBindingInWrapperTrueInitial() {
              Boolean initialValue = Boolean.TRUE;
              ObjectProperty<Boolean> p = new SimpleObjectProperty<Boolean>(initialValue);
              assertTrue(p.get());
              BooleanProperty wrap = BooleanProperty.booleanProperty(p);
              assertEquals("wrapper property value must be same", p.getValue(), wrap.getValue());
              assertEquals("wrapped property value must be unchanged", initialValue, p.getValue());
          }

            msladecek Martin Sládeček
            fastegal Jeanette Winzenburg
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: