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

Cannot recover null values

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      Mappings on ObservableValues never pass through nulls, even if null is a valid instance of the parameterized type and wouldn't be for the mapped type.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Declare nullable ObservableValue, map it to non-null ObservableValue

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      mapped ObservableValue never contains null
      ACTUAL -
      null is casted to result type

      ---------- BEGIN SOURCE ----------
      ObservableValue<@Nullable String> input = new SimpleObjectProperty<>(null);
      ObservableValue<@NotNull Integer> output = input.map(text -> {
        if (text == null) {
          return 0;
        } else {
          return text.length();
        }
      });
      assertEquals(0, output.getValue());
      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: