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

ListSelectionModel.setSelectionMode() underspecified

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 10
    • 5.0u85, 9
    • client-libs

    Description

      This is a rec-creation of https://bugs.openjdk.java.net/browse/JDK-6463710
      which had to be backed out under https://bugs.openjdk.java.net/browse/JDK-8190475


      FULL PRODUCT VERSION :
      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_06-b05, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux ubuntu 2.6.12-10-amd64-generic #1 Fri Apr 28 13:18:42 UTC 2006 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      The setSelectionMode() specification doesn't say what happens to the existing selections when changing from a less restrictive mode to a more restrictive mode (for example, from SINGLE_INTERVAL_SELECTION to SINGLE_SELECTION).

      It appears that the current implementation doesn't modify the selections at all, which leaves the model in an inconsistent state. See the example below, where a model ends up in SINGLE_SELECTION mode with two items selected.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See executable test case.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect at most 1 item to remain selected. Or perhaps the change of mode should clear all current selections.
      ACTUAL -
      Item 1 is selected : true
      Item 2 is selected : true
      1.5.0_06


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.DefaultListSelectionModel;
      import javax.swing.ListSelectionModel;

      public class ListSelectionModelTest {

          public static void main(String[] args) {
              System.out.println("Running on: " + System.getProperty("java.version"));
              DefaultListSelectionModel m = new DefaultListSelectionModel();
              m.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
              m.setSelectionInterval(1, 2);
              m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              System.out.println("Item 1 is selected : " + m.isSelectedIndex(1));
              System.out.println("Item 2 is selected : " + m.isSelectedIndex(2));
          }
      }

      ---------- END SOURCE ----------

      Attachments

        Issue Links

          Activity

            People

              pbansal Pankaj Bansal (Inactive)
              prr Philip Race
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: