-
Bug
-
Resolution: Fixed
-
P3
-
8u77
Scenario:
- register a listener on the table's visibleLeafColumns
- add a tableColumn
- access the newly added column in the listener
- expected: column.getTableView is the table that the column was added to
- actual: column.getTableView is null
failing test case to reproduce:
/**
* Issue: leaf column notification before the added column is fully updated.
*/
@Test
public void testLeafColumnNotification() {
TableView table = new TableView(); //Person.persons());
TableColumn first = new TableColumn("First Name");
table.getColumns().add(first);
table.getVisibleLeafColumns().addListener((ListChangeListener) c -> {
c.next();
assertTrue(c.wasAdded());
assertSame(table, ((TableColumn) c.getAddedSubList().get(0)).getTableView());
});
TableColumn last = new TableColumn("Last Name");
table.getColumns().add(0, last);
}
Reason is the columnsObserver in TableView, which updates the visibleLeafColumns before configuring the tableColumn, something like
updateVisibleLeafColumns();
if (c.wasAdded() {
column.setTableView(TableView.this) ;
Fix should (?!) be simple by reversing the sequence.
Note that I raised the priority because it causes NPEs in custom listeners which took me (and probably will others) quite a while to track down ... It's utterly unexpected that the column isn't fully configured on receiving the notification, after all, we just added it, so we must be able to rely on complete internal configuration of a column.
- register a listener on the table's visibleLeafColumns
- add a tableColumn
- access the newly added column in the listener
- expected: column.getTableView is the table that the column was added to
- actual: column.getTableView is null
failing test case to reproduce:
/**
* Issue: leaf column notification before the added column is fully updated.
*/
@Test
public void testLeafColumnNotification() {
TableView table = new TableView(); //Person.persons());
TableColumn first = new TableColumn("First Name");
table.getColumns().add(first);
table.getVisibleLeafColumns().addListener((ListChangeListener) c -> {
c.next();
assertTrue(c.wasAdded());
assertSame(table, ((TableColumn) c.getAddedSubList().get(0)).getTableView());
});
TableColumn last = new TableColumn("Last Name");
table.getColumns().add(0, last);
}
Reason is the columnsObserver in TableView, which updates the visibleLeafColumns before configuring the tableColumn, something like
updateVisibleLeafColumns();
if (c.wasAdded() {
column.setTableView(TableView.this) ;
Fix should (?!) be simple by reversing the sequence.
Note that I raised the priority because it causes NPEs in custom listeners which took me (and probably will others) quite a while to track down ... It's utterly unexpected that the column isn't fully configured on receiving the notification, after all, we just added it, so we must be able to rely on complete internal configuration of a column.