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

(bf) CharBuffer.wrap throws exception when given empty char array

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.6

      Description



      Name: auR10023 Date: 10/10/2001


      java.nio.CharBuffer.wrap(char[], int, int) throws unexpected
      IllegalArgumentException with empty character array.

      Here is the example:

      ------test.java----

      import java.nio.*;

      class t {
          public static void main (String [] args) {
              char [] array = new char[0];
              try {
                  CharBuffer.wrap(array,1,2);
                  System.out.println("IndexOutOfBoundsException was expected");
                  return;
              } catch (IndexOutOfBoundsException e) {
              }
          }
      }

      -----output:----

      #java -version
      java version "1.4.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b81)
      Java HotSpot(TM) Client VM (build 1.4.0-beta3-b81, mixed mode)

      #java test

      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.CharBuffer.<init>(CharBuffer.java:229)
              at java.nio.HeapCharBuffer.<init>(HeapCharBuffer.java:47)
              at java.nio.CharBuffer.wrap(CharBuffer.java:298)
              at test.main(test.java:7)

      Following methods also fails due to this reason:

      java.nio.ByteBuffer.wrap(char[], int, int)
      java.nio.DoubleBuffer.wrap(char[], int, int)
      java.nio.FloatBuffer.wrap(char[], int, int)
      java.nio.IntBuffer.wrap(char[], int, int)
      java.nio.LongBuffer.wrap(char[], int, int)
      java.nio.ShortBuffer.wrap(char[], int, int)


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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mr Mark Reinhold
              Reporter:
              avusunw Avu Avu (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: