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

NPE on clearing value of IntegerSpinnerValueFactory

    XMLWordPrintable

Details

    • b03
    • generic
    • generic

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 11
      openjdk version "17.0.1" 2021-10-19
      OpenJDK Runtime Environment Temurin-17.0.1+12 (build 17.0.1+12)
      OpenJDK 64-Bit Server VM Temurin-17.0.1+12 (build 17.0.1+12, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      The only way of clearing the content of spinners is to set the value of the corresponding value factory to null which is then treated by the toString(...) functions of the value factories.
      When setting null as the value of an IntegerSpinnerValueFactory the value is cleared but an NullPointerException occurs in an attached listener handling value changes.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create an empty JavaFX project
      2. Create a spinner whose value factory is a IntegerSpinnerValueFactory
      3. Set the value hold by the value factory to null

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Empty spinner text field
      ACTUAL -
      Empty spinner text field while throwing a NullPointerException

      ---------- BEGIN SOURCE ----------
      package com.example.integerspinnermissingnullcheck;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Spinner;
      import javafx.scene.control.SpinnerValueFactory;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class FooApplication extends Application {
          @Override
          public void start(Stage stage) {
              var spinner = new Spinner<>(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 10));
              spinner.getValueFactory()
                      .setValue(null);

              var container = new VBox(spinner);
              var scene = new Scene(container);

              stage.setTitle("There's no null check similar to the one of DoubleSpinnerValueFactory");
              stage.setScene(scene);
              stage.show();
          }

          public static void main(String[] args) {
              launch();
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              aghaisas Ajit Ghaisas
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: