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

(spec) RandomAccessFile.read(byte[] b, int off, int len) needs updates for off param and exceptions

XMLWordPrintable

    • b73
    • x86
    • linux

      FULL PRODUCT VERSION :
       1.5.0_04-b05

      ADDITIONAL OS VERSION INFORMATION :
       Linux 2.4.20-8smp

      A DESCRIPTION OF THE PROBLEM :
      The javadoc for the read(byte[] b, int off, int len) for RandomAccessFile does not give proper documentation as to how the method behaves. The doc descrbes the parameter off as follows:
      off - the start offset of the data.
      However, it also states that this method behaves exactly the same as the read(byte[] b, int off, int len) for InputStream.read(byte[] b, int off, int len) , but the javadoc for InputStream.read(byte[] b, int off, int len) describes off parameter as follows:
      off - the start offset in array b at which the data is written.
      I consistently get array index out of bounds exceptions when I pass in a point in the file where I would like to read my data from.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Declare a byte array with size 64, and try to pass in 64 for off for the RandomAccessFile.read(byte[] b, int off, int len) method. The javadoc for InputStream.read(byte[] b, int off, int len) states that " If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown," which is exactly what happens.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Either javadoc should be fixed to represent the proper usage of the off parameter for RandomAccessFile.read(byte[] b, int off, int len), or the method should be fixed to behave as described.
      ACTUAL -
      off is not used as described by the javadoc for randomAccessFile.read(byte[] b, int off, int len)

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      IndexOutOfBoundException

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Byte[] b = new byte[64];
      raFile.read(b,64,b.length);
      ---------- END SOURCE ----------

            jhangalsunw Jayalaxmi Hangal (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: