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

Tree/TablePosition: must not throw NPE on instantiating with null table

    XMLWordPrintable

    Details

      Description

      Failing test (same for TreeTablePosition):

          @Test
          public void testNullTable() {
              new TablePosition<>(null, 2, new TableColumn<>());
          }
          
      As null handling is not spec'ed in the constructor's doc, options to fix would be

      - change the doc to explicitly disallow null
      - fix the implementation to not throw

      My take is clearly the latter (in no particular order):

      - a position might be used unrelated to a specific table: used to mark f.i. a particular cell in any table
      - users are warned to expect a null (f.i. in doc of constructor and getColumn), so formally supporting it wouldn't make a difference to client code
      - the NPE (for TableView) is introduced in JDK-8093105, looks like it happend accidentally when supporting access to the underlying row object

      blowing code:

          List<S> items = tableView.getItems();

      fix to

          List<S> items = tableView != null ? tableView.getItems() : null;

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              fastegal Jeanette Winzenburg
              Reporter:
              fastegal Jeanette Winzenburg
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: