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

(bf) ByteBuffer.wrap(byte[],int,int) raises wrong exception

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta3
    • CPU:
      sparc
    • OS:
      solaris_2.6, solaris_7, solaris_8
    • Verification:
      Verified

      Description



      Name: auR10023 Date: 06/18/2001



      Method java.nio.ByteBuffer.wrap(byte[],int,int) should raise
       IndexOutOfBoundsException instead of IllegalArgumentException.

      The javadoc contains following lines:

      ...
      public static ByteBuffer wrap(byte[] array,
                                    int offset,
                                    int length)
      ...

      Throws:
                IndexOutOfBoundsException - If the preconditions on the offset and
                length parameters do not hold
      ...
       
      Here is the example:

      ------wrap.java------
       
      import java.nio.*;
       
      class wrap {
          public static void main(String [] args) {
              ByteBuffer.wrap(new byte[10], 0, 11);
          }
      }

      ---- output: ----

      Exception in thread "main" java.lang.IllegalArgumentException
              at java.nio.Buffer.limit(Buffer.java:239)
              at java.nio.Buffer.<init>(Buffer.java:166)
              at java.nio.ByteBuffer.<init>(ByteBuffer.java:229)
              at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:47)
              at java.nio.ByteBuffer.wrap(ByteBuffer.java:298)
              at wrap.main(wrap.java:5)

      The same words are acceptable for the following methods:

      java.nio.CharBuffer.wrap(char[], int, int)
      java.nio.DoubleBuffer.wrap(double[], int, int)
      java.nio.FloatBuffer.wrap(float[], int, int)
      java.nio.IntBuffer.wrap(int[], int, int)
      java.nio.LongBuffer.wrap(long[], int, int)
      java.nio.ShortBuffer.wrap(short[], int, int)

      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              iris Iris Clark
              Reporter:
              avusunw Avu Avu (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: