-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
8u40
-
8u40b15
To reproduce:
- run
- click header
- expected: data sorted
- actual: NPE thrown
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at javafx.scene.control.TableView.sort(TableView.java:1508)
at javafx.scene.control.TableView.doSort(TableView.java:1578)
at javafx.scene.control.TableView.lambda$new$37(TableView.java:532)
at javafx.scene.control.TableView$$Lambda$86/19352785.onChanged(Unknown Source)
Similar toRT-37674, the options to fix are
- either allow null as value and make sure that each and every internal access is guarded against null
- or disallow and clearly document that it is not a valid value (and cleanup internals and remove all guards)
/**
* Issue TableView throws NPE on sorting column if selectionModel property value is null.
*
* @author Jeanette Winzenburg, Berlin
*/
public class TableSortNPEIfNullSelectionModel extends Application {
private final ObservableList<Locale> data =
FXCollections.observableArrayList(Locale.getAvailableLocales()
);
private Parent getContent() {
// instantiate the table with null items
TableView<Locale> view = new TableView<Locale>(data);
TableColumn<Locale, String> column = new TableColumn<>(
"Language");
column.setCellValueFactory(new PropertyValueFactory<>("displayLanguage"));
// either click on header for sorting
view.getColumns().addAll(column);
view.setSelectionModel(null);
// or add column to sort order immediately
//view.getSortOrder().add(column);
Pane parent = new HBox(100);
parent.getChildren().addAll(view);
parent.setPadding(new Insets(20));
return parent;
}
@Override
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(getContent());
primaryStage.setTitle(System.getProperty("java.version"));
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch();
}
}
- run
- click header
- expected: data sorted
- actual: NPE thrown
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at javafx.scene.control.TableView.sort(TableView.java:1508)
at javafx.scene.control.TableView.doSort(TableView.java:1578)
at javafx.scene.control.TableView.lambda$new$37(TableView.java:532)
at javafx.scene.control.TableView$$Lambda$86/19352785.onChanged(Unknown Source)
Similar to
- either allow null as value and make sure that each and every internal access is guarded against null
- or disallow and clearly document that it is not a valid value (and cleanup internals and remove all guards)
/**
* Issue TableView throws NPE on sorting column if selectionModel property value is null.
*
* @author Jeanette Winzenburg, Berlin
*/
public class TableSortNPEIfNullSelectionModel extends Application {
private final ObservableList<Locale> data =
FXCollections.observableArrayList(Locale.getAvailableLocales()
);
private Parent getContent() {
// instantiate the table with null items
TableView<Locale> view = new TableView<Locale>(data);
TableColumn<Locale, String> column = new TableColumn<>(
"Language");
column.setCellValueFactory(new PropertyValueFactory<>("displayLanguage"));
// either click on header for sorting
view.getColumns().addAll(column);
view.setSelectionModel(null);
// or add column to sort order immediately
//view.getSortOrder().add(column);
Pane parent = new HBox(100);
parent.getChildren().addAll(view);
parent.setPadding(new Insets(20));
return parent;
}
@Override
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(getContent());
primaryStage.setTitle(System.getProperty("java.version"));
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch();
}
}
- duplicates
-
JDK-8187145 (Tree)TableView with null selectionModel: throws NPE on sorting
- Resolved
- relates to
-
JDK-8230098 NPEs in ListView with no SelectionModel
- Closed