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

java.lang.String.startsWith method doesn't work with large values of toffset

    XMLWordPrintable

Details

    • 1.1
    • sparc
    • solaris_2.5
    • Not verified

    Description



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


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

      The java.lang.String.startsWith method does not work with
      large values of toffset parameter according to the
      Java language specification.

      The Java Language specification (Version 1.0, August 1, 1996)
      says the following (please see item 20.12.21):

      "20.12.21 public boolean startsWith(String prefix, int toffset)
      throws NullPointerException

      The result is true if and only if the character sequence represented by the
      argument is a prefix of the substring of this String object starting at index
      toffset.

      If prefix is null, then a NullPointerException is thrown.

      The result is false if toffset is negative or greater than the length of this
      String object; otherwise, the result is the same as the result of the
      expression

      this.subString(toffset).startsWith(prefix)"


      Here is the minimized test demonstrating the bug:

      ----- java_lang_String_startsWith.java ---------------------------------------
      class java_lang_String_startsWith {
        public static void main(String argv[]) {
          try {
            boolean b="some string".startsWith("other",Integer.MAX_VALUE);
            if(!b)
              System.out.println("Test passed: b = " + b);
            else
              System.out.println("Test failed: b = " + b);
          } catch(Throwable e) {
            System.out.println("Test failed: unexpected <"+e+"> is thrown");
          }
        }
      }

      ----- The output of the test: -------------------------
      Test failed: unexpected <java.lang.ArrayIndexOutOfBoundsException: 2147483647> is thrown
      -------------------------------------------------------

       

      Attachments

        Activity

          People

            jrose John Rose
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: