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

JList.getSelectedValuesList fails if JList.setSelectionInterval larger than list

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b07
    • CPU:
      x86
    • OS:
      generic

      Description

      FULL PRODUCT VERSION :
      java version "1.7.0_01"
      Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
      Java HotSpot(TM) 64-Bit Server VM (build 21.1-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      If all elements of a JList are preselected using addSelectionInterval and indices are larger than the list, then getSelectedValuesList() will fail with an OutOfBound exception (note that the deprecated getSelectedValues will fail as well)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      // Create a JList with 2 elements
      DefaultListModel<String> dlm = new DefaultListModel<String>();
      list = new JList<String>(dlm);
      list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
      dlm.addElement("1");
      dlm.addElement("2");

      // Set the selection interval too large (3 elements instead of 2)
      list.addSelectionInterval(0, 2);

      list.getSelectedValuesList()
      will trigger java.lang.ArrayIndexOutOfBoundsException: 2 >= 2
      at java.util.Vector.elementAt(Vector.java:470)
      at javax.swing.DefaultListModel.getElementAt(DefaultListModel.java:89)
      at javax.swing.JList.getSelectedValuesList(JList.java:2303)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected all selected elements or an exception at addSelectionInterval saying that the interval was incorrect
      ACTUAL -
      java.lang.ArrayIndexOutOfBoundsException: 2 >= 2
      at java.util.Vector.elementAt(Vector.java:470)
      at javax.swing.DefaultListModel.getElementAt(DefaultListModel.java:89)
      at javax.swing.JList.getSelectedValuesList(JList.java:2303)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      Set the selection interval properly.

        Attachments

          Activity

            People

            Assignee:
            pbansal Pankaj Bansal (Inactive)
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: