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

NPE when table items are set to null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • jfx23
    • jfx21
    • javafx
    • b01
    • generic
    • generic

        When table items are set to null after items were shown first (non-null), a NPE can happen.

        Stacktrace:
        Exception in thread "JavaFX Application Thread" java.lang.NullPointerException: Cannot invoke "javafx.collections.ObservableList.size()" because the return value of "javafx.scene.control.TableView.getItems()" is null
        at javafx.controls/javafx.scene.control.skin.TableSkinUtils.getItemCount(TableSkinUtils.java:212)
        at javafx.controls/javafx.scene.control.skin.TableViewSkinBase.updateContentWidth(TableViewSkinBase.java:909)
        at javafx.controls/javafx.scene.control.skin.TableViewSkinBase.checkContentWidthState(TableViewSkinBase.java:594)
        at javafx.controls/javafx.scene.control.skin.TableViewSkinBase.layoutChildren(TableViewSkinBase.java:514)
        at javafx.controls/javafx.scene.control.Control.layoutChildren(Control.java:612)
        at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1208)

        Technically a regression from JDK-8137244.

        Code:

        import javafx.application.Application;
        import javafx.beans.property.SimpleStringProperty;
        import javafx.scene.Scene;
        import javafx.scene.control.TableColumn;
        import javafx.scene.control.TableView;
        import javafx.stage.Stage;

        public class TableViewBug extends Application {

            @Override
            public void start(Stage stage) {
                TableView<String> tableView = new TableView<>();

                TableColumn<String, String> col = new TableColumn<>("123");
                col.setCellValueFactory(e -> new SimpleStringProperty(e.getValue()));
                tableView.getColumns().add(col);

                tableView.getItems().addAll("1", "2", "3");

                stage.setScene(new Scene(tableView));
                stage.show();

                tableView.setItems(null);
            }

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

        }

              mhanl Marius Hanl
              mhanl Marius Hanl
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: