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

Tree/TableCell: cancel event must return correct editing location

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • jfx17
    • 8, 9, 10
    • javafx
    • java9-ea-u180

      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);
          }
      }

            fastegal Jeanette Winzenburg
            fastegal Jeanette Winzenburg
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: