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

DefaultListModel.removeRange does not throw IllegalArgumentException

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      tiger
    • CPU:
      sparc
    • OS:
      solaris_2.6

      Description



      Name: asR10047 Date: 06/05/2001


      javax.swing.DefaultListModel.removeRange( fromIndex, toIndex) does not follow
      specification. As specification says if fromIndex > toIndex
      an IllegalArgumentException should be thrown but the implementation does
      not do it.

      (See JavaDoc comments)
      public void removeRange(int fromIndex,
                              int toIndex)

           Deletes the components at the specified range of indexes. The removal is
           inclusive, so specifying a range of (1,5) removes the component at index 1 and
           the component at index 5, as well as all components in between.

           Throws an ArrayIndexOutOfBoundsException if the index was invalid. Throws an
           IllegalArgumentException if fromIndex > toIndex.


      Here is the example demonstrating the bug:
      ------------------ Test.java -----------------
      import java.awt.Label;
      import javax.swing.DefaultListModel;

      public class Test {
          public static void main(String[] argv) {
              DefaultListModel c = new DefaultListModel();
              Label object = new Label(" JCK TEST ");
              int size = 16;
              for(int i = 0; i < size; i++ ) {
                  c.addElement( object);
              }
              try {
                  c.removeRange( 3, 1);
                  System.out.println("IllegalArgumentException has not been thrown");
                  System.exit(0);
              } catch(IllegalArgumentException aioobe) {
              }
              System.out.println( "OKAY" );
          }
      }
      -------------- Output from the test -----------------
      IllegalArgumentException has not been thrown
      ------------------------------------------------------

      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            apikalev Andrey Pikalev
            Reporter:
            anssunw Ans Ans (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: