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

InputStream.read(byte[], int, int) does not work as documented if passed null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.1.6
    • 1.1.1
    • docs
    • None
    • 1.1.6
    • x86
    • windows_95
    • Verified



        Name: joT67522 Date: 09/24/97


        According to the docs on this routine, "If the first argument is
        null, up to len bytes are read and discarded." However, it does
        not do this. Instead, it throws an exception.

        /* Example code */

        import java.io.*;

        public class Test
        {
          public static void main(String[] args) throws IOException
          {
            byte[] buf = new byte[16];
            
            System.in.read(null, 0, 5); // Read and discard first 5 bytes
            System.in.read(buf, 0, 11); // Place next 11 bytes in buf
            System.out.write(buf, 0, 5); // Write out the first 5 bytes in buf
          }
        }

        /* Example output *
        If there was no bug, we would see this:

          C:\> java Test <- we run the progran
          0123456789abcdef <- we enter this
          56789 <- and the program writes this

        However, there is a bug, and instead we see this:

          C:\> java Test
          0123456789abcdef
          java.lang.NullPointerException
            at java.io.BufferedInputStream.read(BufferedInputStream.java:209)
            at Test.main(Test.java:9)

        \* End of example */

        company - SCSU , email - ###@###.###
        ======================================================================

              asommere Alan Sommerer (Inactive)
              johsunw Joon Oh (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: