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

Vector.indexOf(Object, int) and lastIndexOf(Object, int): boundary values unclea

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      kestrel
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Verified

      Description



      Name: saC57035 Date: 07/06/99



      Specification for method java.util.Vector.indexOf(Object obj, int index) does not
      explain its behavour for index < 0. In jdk1.2.2 it throws ArrayIndexOutOfBoundsException
      while no Exception or IllegalArgumentException expected

      The same problem exists in the specs of lastIndexOf().


      ----------- Javadoc cite
      Returns the index of the first occurrence of the object argument in this vector at position index or
      later in the vector, that is, the smallest value k such that elem.equals(elementData[k]) && (k >=
      index) is true; returns -1 if the object is not found.
      -----------
                  
      ======================================================================

      Sometimes jdk1.2.2 can throw ArrayIndexOutOfBoundsException
      when for lastIndexOf(obj, index) index >= size(), sometimes not
      It can return wrong results for obj == null

      ------------Test.java
      import java.util.Vector;

      public class Test {
          public static void main(String [] args) {
              Vector vect = new Vector();
              for(int i=0; i<vect.capacity(); i++) {
                  System.out.println(vect.lastIndexOf(null, i));
              }
          }
      }
      ------------
      0
      1
      2
      3
      4
      5
      6
      7
      8
      9
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
              at java.util.Vector.lastIndexOf(Vector.java, Compiled Code)
              at Test.main(Test.java, Compiled Code)
      ------------

      ###@###.### 1999-07-08

        Attachments

          Activity

            People

            Assignee:
            jjb Josh Bloch
            Reporter:
            savzan Stanislav Avzan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: