Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8315723 | jfx17.0.9 | Jose Pereda | P4 | Resolved | Fixed | b03 |
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: fixedJDK-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");
// workaroundJDK-8251481
name.setPrefWidth(200);
name.setCellValueFactory(cc -> new SimpleStringProperty(cc.getValue()));
name.setCellFactory(cc -> new TableCell<String, String>() {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText("");
} else {
// access a property of row's item
// NPE because item is null during update after items modification
setText(item + getTableRow().getItem().toString());
}
}
});
table.getColumns().addAll(name);
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;
}
@Override
public void start(Stage stage) throws Exception {
stage.setScene(new Scene(createContent(), 400, 200));
//stage.setTitle(FXUtils.version());
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
- 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
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
name.setPrefWidth(200);
name.setCellValueFactory(cc -> new SimpleStringProperty(cc.getValue()));
name.setCellFactory(cc -> new TableCell<String, String>() {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText("");
} else {
// access a property of row's item
// NPE because item is null during update after items modification
setText(item + getTableRow().getItem().toString());
}
}
});
table.getColumns().addAll(name);
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;
}
@Override
public void start(Stage stage) throws Exception {
stage.setScene(new Scene(createContent(), 400, 200));
//stage.setTitle(FXUtils.version());
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
- backported by
-
JDK-8315723 TableCell: NPE on modifying item's list
- Resolved
- relates to
-
JDK-8289751 Multiple unit test failures after JDK-8251483
- Resolved
-
JDK-8115269 TableRow "item" property is being updated out of order
- Resolved
-
JDK-8289357 (Tree)TableView is null in (Tree)TableRowSkin during autosize
- Resolved
- links to
-
Commit openjdk/jfx17u/0985af97
-
Commit openjdk/jfx/222b2b11
-
Review openjdk/jfx17u/152
-
Review openjdk/jfx/741
(3 links to)