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

Tree/TableView: implementation of isSelected(int) violates contract

    Details

      Description

      Happens in single mode with cell selection enabled:

      failing test (for TableViewSelectionModelImplTest)

          /**
           * Analysing failing tests when fixing JDK-8219720.
           *
           * Suspect: isSelected(int row) violates contract.
           *
           * @see #selectRowWhenInSingleCellSelectionMode()
           * @see #selectRowWhenInSingleCellSelectionMode2()
           */
          @Test
          public void testSelectRowWhenInSingleCellSelectionModeIsSelected() {
              model.setSelectionMode(SelectionMode.SINGLE);
              model.setCellSelectionEnabled(true);
              model.select(3);
              // test against contract
              assertEquals("selected index", 3, model.getSelectedIndex());
              assertTrue("contained in selected indices", model.getSelectedIndices().contains(3));
              // test against spec
              assertEquals("is selected index", model.getSelectedIndices().contains(3), model.isSelected(3)); }

      The spec for selectionModel.isSelected(int):

      "Convenience method to inform if the given index is currently selected in this SelectionModel. Is functionally equivalent to calling getSelectedIndices().contains(index)"

      (ignoring the obvious doc error, getSelectedIndices is declared in subclass ;)

      Technical reason is that isSelected(int) delegates to isSelect(int, TableColumn) with null as second parameter. Given the spec of the latter method:

      "If the table control is in its 'cell selection' mode (where individual cells can be selected, rather than entire rows), and if the column argument is null, this method should return true only if all cells in the given row are selected"

      the latter must (and does) return false always in single mode and columns.size() > 1.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                fastegal Jeanette Winzenburg
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: