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

ClassCastException when unbinding observable lists

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 8u66
    • javafx
    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.8.0_66"
      Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Win 7 64bit

      A DESCRIPTION OF THE PROBLEM :
      This seems to be a simple copy paste error in de BidirectionalBinding method
      It seems property2 shoud not be cast to ObservableValue but Observable or the other way round (instanceof should be ObservableValue)

       public static void unbind(Object property1, Object property2) {
              checkParameters(property1, property2);
              final BidirectionalBinding binding = new UntypedGenericBidirectionalBinding(property1, property2);
              if (property1 instanceof ObservableValue) {
                  ((ObservableValue) property1).removeListener(binding);
              }
              if (property2 instanceof Observable) {
                  ((ObservableValue) property2).removeListener(binding);
              }
          }

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the attached test case

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      unbindBidirectional(a,b) should unbind the content of both lists
      ACTUAL -
      Classcast Exception is thrown

      java.lang.ClassCastException: com.sun.javafx.collections.ObservableListWrapper cannot be cast to javafx.beans.value.ObservableValue
      at com.sun.javafx.binding.BidirectionalBinding.unbind(BidirectionalBinding.java:108)
      at javafx.beans.binding.Bindings.unbindBidirectional(Bindings.java:795)
      at ch.schiller.semaft.UnbindTest.testOnCreate(UnbindTest.java:22)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------


      import javafx.beans.binding.Bindings;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import org.junit.Test;

      /**
       *
       * @author Patrick.Schmid
       */
      public class UnbindTest
      {

        @Test
        public void testOnCreate()
        {
          ObservableList a = FXCollections.observableArrayList();
          ObservableList b = FXCollections.observableArrayList();

          Bindings.bindContentBidirectional(a, b);
          Bindings.unbindBidirectional(a, b);
        }
      }

      ---------- END SOURCE ----------

            vadim Vadim Pakhnushev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: