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

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

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta3
    • CPU:
      sparc
    • OS:
      solaris_7
    • Verification:
      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

            Assignee:
            iris Iris Clark
            Reporter:
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: