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

TableCell: NPE on modifying item's list



    • Bug
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • 8u261, 9.0.4, jfx14
    • jfx19
    • javafx


      The example has a custom cell that uses a property of the row's item to configure its own visuals. To reproduce the NPE, compile and run

      - press the button to modify the items list (note: the type of modification doesn't matter)
      - expected: modification updates the table without error
      - actual: throws NPE

      Technically, the error is that at some time during the update process the row is empty (aka: item == null) while cell is not empty. Both should be in sync always, just the same as for the sync of the item (see: fixed JDK-8115269): that is either message the cell update only if the row item is complete or implement the cell update to regard itself as empty if the row is empty.

      The example:

          public class TableCellRowItemNPE extends Application {
              private Parent createContent() {
                  TableView<String> table = new TableView<>(FXCollections.observableArrayList
                          ("short name", "and now really really longish name that exceeds all"));
                  TableColumn<String, String> name = new TableColumn<>("Name");
                  // workaround JDK-8251481
                  name.setCellValueFactory(cc -> new SimpleStringProperty(cc.getValue()));
                  name.setCellFactory(cc -> new TableCell<String, String>() {
                      protected void updateItem(String item, boolean empty) {
                          super.updateItem(item, empty);
                          if (empty) {
                          } else {
                              // access a property of row's item
                              // NPE because item is null during update after items modification
                              setText(item + getTableRow().getItem().toString());
                  Button add = new Button("add item");
                  add.setOnAction(e -> table.getItems().add("added"));
                  BorderPane content = new BorderPane(table);
                  content.setBottom(new HBox(10, add));
                  return content;
              public void start(Stage stage) throws Exception {
                  stage.setScene(new Scene(createContent(), 400, 200));
              public static void main(String[] args) {


        Issue Links



              mhanl Marius Hanl
              fastegal Jeanette Winzenburg
              0 Vote for this issue
              3 Start watching this issue