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

(bf) Unexpected behavior of StringCharBuffer.subSequence for values of start,end

    XMLWordPrintable

Details

    • beta3
    • sparc
    • solaris_7
    • Verified

    Description

      Unexpected behaviour from StringCharBuffer.subSequence(int start,int end)
      when preconditions on start and end are not met.

      For:
      end < 0: IllegalArgumentException thrown instead of IndexOutOfBoundsException.

      start > remaining() : IllegalArgumentException thrown instead of
                            IndexOutOfBoundsException.

      end > remaining(): IndexOutOfBoundsException not thrown.(no exception thrown)

      end < start : IllegalArgumentException thrown instead of
                    IndexOutOfBoundsException.
      --------------------------------------------------------------------------------
      String source = "This is the string used to test subSequence() method";
       StringCharBuffer c = (StringCharBuffer)(CharBuffer.wrap(source));

       // end < 0
       try {
         c.subSequence(1,-3);
         System.out.println("IndexOutOfBoundsException not thrown for end < 0");
       }
       catch(IndexOutOfBoundsException e) {
         System.out.println("Expected IndexOutOfBoundsException for end < 0");
       }
       catch(Exception e) {
         System.out.println(e.toString()+" thrown instead of IndexOutOfBoundsException for end < 0");
       }

       // start > remaining()
       try {
         c.subSequence(c.remaining()+1,3);
         System.out.println("IndexOutOfBoundsException not thrown for start > remaining");
       }
       catch(IndexOutOfBoundsException e) {
         System.out.println("Expected IndexOutOfBoundsException for start > remaining");
       }
       catch(Exception e) {
         System.out.println(e.toString()+" thrown instead of IndexOutOfBoundsException for start > remaining");
       }

       // end > remaining()
       try {
         StringCharBuffer c2 = (StringCharBuffer)(CharBuffer.wrap(source));
         c2.subSequence(1,c2.remaining()+1);
         System.out.println("IndexOutOfBoundsException not thrown for end > remaining");
       }
       catch(IndexOutOfBoundsException e) {
         System.out.println("Expected IndexOutOfBoundsException for end > remaining");
       }
       catch(Exception e) {
         System.out.println(e.toString()+" thrown instead of IndexOutOfBoundsException for end > remaining");
       }

       // end < start
       try {
         c.subSequence(5,1);
         System.out.println("IndexOutOfBoundsException not thrown for end < start");
       }
       catch(IndexOutOfBoundsException e) {
         System.out.println("Expected IndexOutOfBoundsException for end < start");
       }
       catch(Exception e) {
         System.out.println(e.toString()+" thrown instead of IndexOutOfBoundsException for end < start");
       }

      ###@###.### 2001-10-04
      StringCharBuffer is no longer a public class. Since the bug is similar to 4416536. Will test the functionality in 4416536.

      Attachments

        Activity

          People

            iris Iris Clark
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: