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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u5
    • Fix Version/s: 8u20
    • Component/s: javafx
    • Labels:
    • Subcomponent:

      Description

      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());
          }

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported: