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

java.io.XXXXInputStream.read(b,off,len) methods work wrong with b

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2beta4
    • CPU:
      generic, sparc
    • OS:
      generic, solaris_2.5
    • Verification:
      Not verified

      Description

      This bug was found by St.Petersburg Java SQE team (by Stanislav Avzan).

      The java.io.StringBufferInputStream.read(b,off,len) method does not work with null value of b according to the Java language specification.

      The Java Language specification
      (Version 1.0 - August 1, 1996)
      says the following (please see item 22.3.3):

      22.3.3 public int read(byte[] b, int off, int len)
      throws IOException, NullPointerException,
      IndexOutOfBoundsException

      The general contract of read(b, off, len) is that it reads some number
      of bytes from the input stream and stores them into the buffer array b. An
      attempt is made to read as many as len bytes, but a smaller number may
      be read, possibly zero. The number of bytes actually read is returned as
      an integer.

      This method blocks until input data is available, end of file is detected, or
      an exception is thrown.

      If b is null, a NullPointerException is thrown. <.....>"

      So this method should throw NullPointerException
      if b is null.
      But in fact when len equals to 0 it does not.
      The same error against PipedInputStream was filed as 1266815.
       
      Here is the minimized test demonstrating the bug:
          
      ----- test21.java ---------------------------------------
      import java.io.*;

      public class test21 {

         public static void main( String[] argv ) {
           StringBufferInputStream is = new StringBufferInputStream("Test");
           try {
             is.read(null,0,0);
             System.out.println("Test failed: NullPointerException expected");

           } catch(NullPointerException e) {
             System.out.println("Test passed: NullPointerException thrown");
           } catch(Throwable e) {
             System.out.println("Test failed: unexpected <"+e+"> thrown");
           }
         }
      }

      ----- The output of the test: -------------------------

      $JAVA test21
      Test failed: NullPointerException expected

      -------------------------------------------------------



      Name: saC57035 Date: 11/27/96


      This bug was found by St.Petersburg Java SQE team (by Stanislav Avzan).

      The java.io.InputStream.read(b,off,len) and java.io.StringBufferInputStream.read(b,off,len)
      methods don't work with null value of b according to the Java language specification.

      The Java Language specification
      (Version 1.0 - August 1, 1996)
      says the following (please see item 22.3.3):

      22.3.3 public int read(byte[] b, int off, int len)
      throws IOException, NullPointerException,
      IndexOutOfBoundsException

      The general contract of read(b, off, len) is that it reads some number
      of bytes from the input stream and stores them into the buffer array b. An
      attempt is made to read as many as len bytes, but a smaller number may
      be read, possibly zero. The number of bytes actually read is returned as
      an integer.

      This method blocks until input data is available, end of file is detected, or
      an exception is thrown.

      If b is null, a NullPointerException is thrown. <.....>"

      So this method should throw NullPointerException
      if b is null.
      But in fact when len equals to 0 it does not.
      The same error against PipedInputStream was filed as 1266815.
       
      Here is the minimized test demonstrating the bug for StringBufferInputStream:
          
      ----- test21.java ---------------------------------------
      import java.io.*;

      public class test21 {

         public static void main( String[] argv ) {
           StringBufferInputStream is = new StringBufferInputStream("Test");
           try {
             is.read(null,0,0);
             System.out.println("Test failed: NullPointerException expected");

           } catch(NullPointerException e) {
             System.out.println("Test passed: NullPointerException thrown");
           } catch(Throwable e) {
             System.out.println("Test failed: unexpected <"+e+"> thrown");
           }
         }
      }

      ----- The output of the test: -------------------------

      $JAVA test21
      Test failed: NullPointerException expected

      -------------------------------------------------------



      ----- End Included Message -----

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

      Name: saC57035 Date: 12/02/96


      The similar bugs are found in LineNumberInputStream and PushbackInputStream as well.
      Attention please! All these bugs aren't fixed in 1.1 release!
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dviswanasunw Deepa Viswanathan (Inactive)
              Reporter:
              mgorshen Mikhail Gorshenev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: