-
Bug
-
Resolution: Fixed
-
P4
-
1.0.2, 1.2.0
-
1.2beta4
-
generic, sparc
-
generic, solaris_2.5
-
Not verified
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!
======================================================================
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!
======================================================================
- duplicates
-
JDK-4116080 java.io.InputStream.read(byte[], int, int) does not check for null
-
- Closed
-
- relates to
-
JDK-1266815 The java.io.PipedInputStream.read(b,off,len) method works wrong with b
-
- Closed
-
-
JDK-4213054 modena_jlib2_2/conform/c22_07/c2207602 fails on JTG 1.2 sparc and intel
-
- Closed
-
-
JDK-4105384 java.io.PipedInputStream.read fails when off + len > Integer.MAX_VALUE
-
- Closed
-