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

NullPointerException in empty TableView when querying focused index

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 8u60
    • 8u40
    • javafx
    • Ubuntu 14.10

      java version "1.8.0_40"
      Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
      Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

    Description

      When calling tableView.getSelectionModel().getFocusedIndex() an exception is thrown if the TableView is empty.

      To reproduce just run the example code:

      Example Code:


      package bugreports;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.TableView;
      import javafx.stage.Stage;

      import static javafx.application.Platform.runLater;

      public class TableViewNullPointerException extends Application {

          @Override
          public void start(final Stage primaryStage) throws Exception {
              final TableView<String> view = new TableView<>();

              primaryStage.setScene(new Scene(view));
              primaryStage.show();

              runLater(() -> view.getSelectionModel().getFocusedIndex());
          }
      }


      Workaround for now is something like this:

      int index;
      try {
          index = tableView.getSelectionModel().getFocusedIndex();
      } catch (NullPointerException e) {
         index = -1;
      }

      Attachments

        Activity

          People

            jgiles Jonathan Giles
            cmuthingjfx Clemens Muthing (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: