-
Bug
-
Resolution: Fixed
-
P4
-
jfx11, 8u40, 9
-
java9-ea-u180
-
b12
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8304083 | jfx17.0.7 | Johan Vos | P4 | Resolved | Fixed |
There is also a similar issue with ListView
---
To reproduce: run the example and click into column header to sort -> throws NPE wtih stacktrace:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at javafx.controls/javafx.scene.control.TableView.sort(TableView.java:1569)
at javafx.controls/javafx.scene.control.TableView.doSort(TableView.java:1652)
at javafx.controls/javafx.scene.control.TableView.lambda$new$0(TableView.java:545)
reason seems to be a missing null check in 1569:
final List<TablePosition> prevState = new ArrayList<>(getSelectionModel().getSelectedCells());
The example:
import java.util.Locale;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.SortedList;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
/**
* TableView with null selectionModel: NPE on sorting
*/
public class TableViewNPEWithoutSelectionModel extends Application {
private Parent getContent() {
ObservableList<Locale> data = FXCollections.observableArrayList(
Locale.getAvailableLocales());
SortedList<Locale> sorted = new SortedList<>(data);
TableView<Locale> table = new TableView<>(sorted);
sorted.comparatorProperty().bind(table.comparatorProperty());
table.setSelectionModel(null);
TableColumn<Locale, String> countryCode = new TableColumn<>("CountryCode");
countryCode.setCellValueFactory(new PropertyValueFactory<>("country"));
table.getColumns().addAll(countryCode);
BorderPane pane = new BorderPane(table);
return pane;
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setScene(new Scene(getContent(), 800, 400));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
edit:
- setting a null model should also clear the existing selection in both Tree- and TableView, as well as focused index, since no more selection and cell/row focus is possible.
- backported by
-
JDK-8304083 (Tree)TableView with null selectionModel: throws NPE on sorting
- Resolved
- duplicates
-
JDK-8090060 TableView with null selectionModel throws NPE on sorting
- Closed
- is cloned by
-
JDK-8296413 Tree/TableView with null focus model throws NPE in queryAccessibleAttribute()
- Resolved
- relates to
-
JDK-8279640 ListView with null SelectionModel/FocusModel throws NPE
- Resolved
- links to
-
Commit openjdk/jfx17u/95bc1eeb
-
Commit openjdk/jfx/58376eb8
-
Review openjdk/jfx17u/123
-
Review openjdk/jfx/876