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

java.util.Vector.removeElementAt method is not compatible to specification

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Not verified

      Description



      Name: saf@russia Date: 08/07/96


      This bug was found by St.Petersburg Java SQE team (by Michael Gorshenev).

      The java.util.Vector.removeElementAt(int) does not work according the specification.

      The Java Language specification
      (Pre-Release Version 1.0, Draft 5.2 - July 3, 1996)
      says the following (please see item 21.11.16):

      "21.11.16 public final void removeElementAt(int index)
      throws IndexOutOfBoundsException

      The size of this Vector is decreased by 1 and the item at the specified
      index is removed from this Vector. Any item in this Vector that was
      previously at index k is first moved to index k-1 if and only if k is greater
      than index."

      The java.util.Vector.removeElementAt(int) with empty vector and parameter -1 does throw ArrayIndexOutOfBoundsException, but it also sets vector size to -1.
       
      Here is the minimized test demonstrating the bug:
          

      ----- java_util_Vector_removeElementAt.java -------------
      class java_util_Vector_removeElementAt {
        
        public static void main(String[] argv) {
            java.util.Vector v=new java.util.Vector();
            try {
              v.removeElementAt(-1);
              System.out.println("Test failed: ArrayIndexOutOfBoundsException is not thrown");
            }
            catch (ArrayIndexOutOfBoundsException e) {
             if (v.size()==0)
              System.out.println("Test passed: vector size = 0");
             else
              System.out.println("Test failed: vector size = " + v.size());
            }
         }
      }

      ----- The output of the test: -------------------------

      $JAVA java_util_Vector_removeElementAt
      Test failed: vector size = -1

      -------------------------------------------------------
       

        Attachments

          Activity

            People

            Assignee:
            mr Mark Reinhold
            Reporter:
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: