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

ReadOnlyBooleanWrapper: Bindings.or & Bindings.and return incorrect results

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8u51
    • Fix Version/s: None
    • Component/s: javafx
    • Labels:
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_51"
      Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      When two ReadOnlyBooleanWrapper objects are bound using Bindings.or, the result is incorrectly evaluated. See for example:

      @Test
      public void testReadOnlyBooleanWrapper() {
          ReadOnlyBooleanWrapper b1 = new ReadOnlyBooleanWrapper(false);
          ReadOnlyBooleanWrapper b2 = new ReadOnlyBooleanWrapper(false);

          BooleanExpression or = b1.or(b2);

          b1.set(true);
          // Here or is expected to be true, but the test fails:
          assertTrue(or.get());
      }

      The reason is that the binding binds to the ReadOnlyProperty of the wrapper, and that makes the short-circuit logic go wrong when it compares the observable that fired the change (an instance of ReadOnlyBooleanWrapper) with the bound argument (an instance of ReadOnlyProperty) in the following code in Bindings.java:

          @Override
          public void invalidated(Observable observable) {
              final BooleanOrBinding binding = ref.get();
              if (binding == null) {
                  observable.removeListener(this);
              } else {
                  // short circuit invalidation. This BooleanBinding becomes
                  // only invalid if the first operator changes or the
                  // first parameter is false.
                  if ((binding.op1.equals(observable) || (binding.isValid() && !binding.op1.get()))) {
                      binding.invalidate();
                  }
              }
          }

      See http://stackoverflow.com/questions/32847074/readonlybooleanwrapper-incorrect-behaviour-when-used-with-bindings-or

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      @Test
      public void testReadOnlyBooleanWrapper() {
          ReadOnlyBooleanWrapper b1 = new ReadOnlyBooleanWrapper(false);
          ReadOnlyBooleanWrapper b2 = new ReadOnlyBooleanWrapper(false);

          BooleanExpression or = b1.or(b2);

          b1.set(true);
          // Here or is expected to be true, but the test fails:
          assertTrue(or.get());
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Test passes
      ACTUAL -
      Test fails

      REPRODUCIBILITY :
      This bug can be reproduced always.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                vadim Vadim Pakhnushev
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: