-
Bug
-
Resolution: Fixed
-
P4
-
8u261, 9.0.4, jfx14
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8315722 | jfx17.0.9 | Jose Pereda | P4 | Resolved | Fixed | b03 |
The example has a custom TableCell that uses the row's item to configure its own visuals. To reproduce the NPE, compile and run
- note that the cells' content is not fully visible (no wonder, we set the column's pref too small ;)
- double click the column's resize region to adjust its width
- expected: column width extended to fit the cell content
- actual: NPE thrown (and column width unchanged)
Technically, the reason is that the row is actually null (due to the cell context not completely setup for measuring its size requirementJDK-8251480).
This behavior is unexpected: client code shouldn't be required to bother with implementation details for certain use-cases but rely on a fully configured cell context if !cell.empty.
The example:
public class TableColumnAutoSizingNPE 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");
// just for control (without, it will throw initially)
name.setPrefWidth(100);
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 item of tableRow:
// NPE on autosizing because row is null
setText(item + getTableRow().getItem());
}
}
});
table.getColumns().addAll(name);
BorderPane content = new BorderPane(table);
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);
}
}
- note that the cells' content is not fully visible (no wonder, we set the column's pref too small ;)
- double click the column's resize region to adjust its width
- expected: column width extended to fit the cell content
- actual: NPE thrown (and column width unchanged)
Technically, the reason is that the row is actually null (due to the cell context not completely setup for measuring its size requirement
This behavior is unexpected: client code shouldn't be required to bother with implementation details for certain use-cases but rely on a fully configured cell context if !cell.empty.
The example:
public class TableColumnAutoSizingNPE 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");
// just for control (without, it will throw initially)
name.setPrefWidth(100);
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 item of tableRow:
// NPE on autosizing because row is null
setText(item + getTableRow().getItem());
}
}
});
table.getColumns().addAll(name);
BorderPane content = new BorderPane(table);
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-8315722 TableCell accessing row: NPE on auto-sizing
- Resolved
- relates to
-
JDK-8251480 TableColumnHeader: calc of cell width must respect row styling
- Resolved
- links to
-
Commit openjdk/jfx17u/2e56cc0e
-
Commit openjdk/jfx/59cd8ec2
-
Review openjdk/jfx17u/150
-
Review openjdk/jfx17u/151
-
Review openjdk/jfx/716
(2 links to)