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

Provide default value for select, valueAt methods

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Unresolved
    • P3
    • tbd
    • 8
    • javafx

    Description

      Consider the following usecase. You have an ObjectProperty of type Image and want to bind some values to its width and height.

      For example, you could do it using select methods:

      protected DoubleBinding photoWidth = Bindings.selectDouble(photo, "width");

      Unfortunately, when image is null there is the following unpleasant stacktrace in the output.

      To avoid it it would be great to provide default value to be returned if any of the selection steps return null. In JavaFX 1.3 days this used to work with default 0 value for numeric bindings, exceptions where never shown for such cases. For
      example, this could be written as following:

      protected DoubleBinding photoWidth = Bindings.selectDouble(photo, 0, "width"); // where 0 is the default value

      WARNING: com.sun.javafx.binding.SelectBinding$SelectBindingHelper getObservableValue Property 'width' in ObjectProperty [value: null] is null
      java.lang.NullPointerException
      at com.sun.javafx.binding.SelectBinding$SelectBindingHelper.getObservableValue(SelectBinding.java:435)
      at com.sun.javafx.binding.SelectBinding$SelectBindingHelper.access$200(SelectBinding.java:384)
      at com.sun.javafx.binding.SelectBinding$AsDouble.computeValue(SelectBinding.java:175)
      at javafx.beans.binding.DoubleBinding.get(DoubleBinding.java:202)
      at javafx.beans.binding.DoubleExpression.getValue(DoubleExpression.java:68)
      at javafx.beans.binding.DoubleBinding.getValue(DoubleBinding.java:111)
      at com.sun.javafx.binding.ExpressionHelper.addListener(ExpressionHelper.java:52)
      at javafx.beans.binding.DoubleBinding.addListener(DoubleBinding.java:121)
      at javafx.beans.binding.DoubleBinding.bind(DoubleBinding.java:152)
      at javafx.beans.binding.Bindings$24.<init>(Bindings.java:1805)
      at javafx.beans.binding.Bindings.divide(Bindings.java:1803)
      at javafx.beans.binding.Bindings.divide(Bindings.java:2034)
      at javafx.beans.binding.DoubleExpression.divide(DoubleExpression.java:217)

      Attachments

        Issue Links

          Activity

            People

              kcr Kevin Rushforth
              mrkam Alexander Kuznetcov (Inactive)
              Votes:
              5 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:
                Imported: