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

ArrayList::removeRange doesn't throw exception when from > to

    XMLWordPrintable

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Java SE version 8 run on Windows-7

      A DESCRIPTION OF THE PROBLEM :
      The second parameter (to exclusive index ) should be bigger or at most equals to the first parameter (from the index).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      try: arr is an ArrayList object
      1. arr.removeRange(3, 4);//exclusive, only last elm: deleted (Ok)
      2. arr.removeRange(3, 3);//nothing happenned: Ok
      3. arr.removeRange(3, 2);//why 1 copy (3), instead of error message
      4. arr.removeRange(3, 1);//why 2 copies (2 & 3), no error message
      5. arr.removeRange(3, 0);//why 3 copies (1, 2 & 3), no error message


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      1. Ok
      2. Ok
      3. running error message
      4. idem
      5. idem
      ACTUAL -
      3. 1 copy instead of error message
      4. 2 copies instead of error message
      5. 3 copies instead of error message

      ---------- BEGIN SOURCE ----------
      import java.util.*;

      public class ALRemRange extends ArrayList<Integer> {
      public static void main(String[] args){
      // create an empty array list
      ALRemRange arr = new ALRemRange();
      // use add() method to add values in the list
      arr.add(1);//idx:0
      arr.add(2);//idx:1
      arr.add(3);//idx:2
      arr.add(4);//idx:3
      System.out.println("The list before using removeRange:" + arr);
      try{//removeRange(from, to exclusive)
      // arr.removeRange(3, 4);//exclusive, only last elm: deleted (Ok)
      // arr.removeRange(3, 3);//nothing happenned: Ok
      // arr.removeRange(3, 2);//why 1 copy (3), instead of error message
      // arr.removeRange(3, 1);//why 2 copies (2 & 3), no error message
      arr.removeRange(3, 0);//why 3 copies (1, 2 & 3), no error message
      }catch(Exception e){System.out.println(e);}
      System.out.println("The list after using removeRange:" + arr);
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      adding if (to>from) clause to prompt the error messages

      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            rpallath Rajendrakumar Pallath
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated: