Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8160771

TableView: newly added tableColumn must be fully configured in notification from visibleLeafColumns

    Details

      Description

      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.

        Attachments

          Activity

            People

            • Assignee:
              jgiles Jonathan Giles
              Reporter:
              fastegal Jeanette Winzenburg
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: