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

TableView: NPE on access of event state on cancel

    Details

    • Type: Bug
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: 8, 9, 10
    • Fix Version/s: tbd
    • Component/s: javafx
    • Environment:

      java9-ea-u180

      Description

      To reproduce, run example, start edit in any cell, cancel edit by ESC
      - expected: print row value
      - actual: NPE

      The underlying reason is the incorrect tablePosition of the edit event: it must be equal to the one received in onEditStart but is null

      The example

      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.scene.Scene;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TablePosition;
      import javafx.scene.control.TableView;
      import javafx.scene.control.cell.PropertyValueFactory;
      import javafx.scene.control.cell.TextFieldTableCell;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      /**
       * TableView: NPE on access of event state on cancel
       */
      public class TableViewEditCancelNPE extends Application {

          TablePosition<TableColumn, String> editPosition;
          @Override
          public void start(Stage primaryStage) {
              TableView<TableColumn> table = new TableView<>(
                      FXCollections.observableArrayList(new TableColumn("first"),
                              new TableColumn("second")));
              table.setEditable(true);

              TableColumn<TableColumn, String> first = new TableColumn<>("Text");
              first.setCellFactory(TextFieldTableCell.forTableColumn());
              first.setCellValueFactory(new PropertyValueFactory<>("text"));

              first.setOnEditStart(t -> editPosition = t.getTablePosition());
              first.setOnEditCancel(t -> {
                  if (!editPosition.equals(t.getTablePosition())) {
                      System.out.println("expected " + editPosition + " actual " + t.getTablePosition());
                      System.out.println("Desaster: NPE on access of event state");
                      t.getRowValue();
                  }
                  
              });
              table.getColumns().addAll(first);

              BorderPane root = new BorderPane(table);
              Scene scene = new Scene(root, 300, 250);

              primaryStage.setTitle("Hello World!");
              primaryStage.setScene(scene);
              primaryStage.show();
          }

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

        Attachments

          Activity

            People

            • Assignee:
              aghaisas Ajit Ghaisas
              Reporter:
              fastegal Jeanette Winzenburg
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: